Skip to content

Commit 20412d5

Browse files
committed
update label rendering logic
1 parent 34506c3 commit 20412d5

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

.changeset/clean-taxes-check.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'@clerk/clerk-js': patch
2+
'@clerk/clerk-js': minor
33
---
44

5-
Update SocialButtons layout to be consistent across desktop and mobile.
5+
Update SocialButtons to show "Continue with" prefix for last auth strategy, and improve mobile layout consistency.

packages/clerk-js/src/ui/elements/SocialButtons.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ export const SocialButtons = React.memo((props: SocialButtonsRootProps) => {
100100
MAX_STRATEGIES_PER_ROW,
101101
lastAuthenticationStrategy,
102102
);
103+
const strategiesCount = lastAuthenticationStrategyPresent ? strategies.length - 1 : strategies.length;
103104
const strategyRowOneLength = strategyRows.at(lastAuthenticationStrategyPresent ? 1 : 0)?.length ?? 0;
105+
const shouldForceSingleColumnOnMobile = !lastAuthenticationStrategyPresent && strategies.length === 2;
104106

105107
const preferBlockButtons =
106108
socialButtonsVariant === 'blockButton'
@@ -153,8 +155,7 @@ export const SocialButtons = React.memo((props: SocialButtonsRootProps) => {
153155
[mqu.sm]: {
154156
// Force single-column on mobile when 2 strategies are present (without last auth) to prevent
155157
// label overflow. When last auth is present, only 1 strategy remains here, so overflow isn't a concern.
156-
gridTemplateColumns:
157-
!lastAuthenticationStrategyPresent && strategies.length === 2 ? 'repeat(1, minmax(0, 1fr))' : undefined,
158+
gridTemplateColumns: shouldForceSingleColumnOnMobile ? 'repeat(1, minmax(0, 1fr))' : undefined,
158159
},
159160
gridTemplateColumns:
160161
strategies.length < 1
@@ -169,19 +170,21 @@ export const SocialButtons = React.memo((props: SocialButtonsRootProps) => {
169170
})}
170171
>
171172
{row.map(strategy => {
172-
const label =
173-
strategies.length === SOCIAL_BUTTON_PRE_TEXT_THRESHOLD
174-
? `Continue with ${strategyToDisplayData[strategy].name}`
175-
: strategyToDisplayData[strategy].name;
173+
const shouldShowPreText =
174+
strategiesCount === SOCIAL_BUTTON_PRE_TEXT_THRESHOLD ||
175+
(strategy === lastAuthenticationStrategy && row.length === 1);
176176

177-
const localizedText =
178-
strategies.length === SOCIAL_BUTTON_PRE_TEXT_THRESHOLD
179-
? localizationKeys('socialButtonsBlockButton', {
180-
provider: strategyToDisplayData[strategy].name,
181-
})
182-
: localizationKeys('socialButtonsBlockButtonManyInView', {
183-
provider: strategyToDisplayData[strategy].name,
184-
});
177+
const label = shouldShowPreText
178+
? `Continue with ${strategyToDisplayData[strategy].name}`
179+
: strategyToDisplayData[strategy].name;
180+
181+
const localizedText = shouldShowPreText
182+
? localizationKeys('socialButtonsBlockButton', {
183+
provider: strategyToDisplayData[strategy].name,
184+
})
185+
: localizationKeys('socialButtonsBlockButtonManyInView', {
186+
provider: strategyToDisplayData[strategy].name,
187+
});
185188

186189
const imageOrInitial = strategyToDisplayData[strategy].iconUrl ? (
187190
<Image

0 commit comments

Comments
 (0)