Skip to content

Commit d33b7b5

Browse files
chore(clerk-js,localizations,types): Localize UserButton and OrgSwitcher triggers (#7086)
1 parent 7dfbf3a commit d33b7b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+225
-26
lines changed

.changeset/pretty-walls-burn.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/localizations': patch
3+
'@clerk/clerk-js': patch
4+
'@clerk/types': patch
5+
---
6+
7+
Localize aria-labels within `UserButton` and `OrganizationSwitcher` triggers.

integration/tests/next-quickstart.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodesQuickstart] })(
4848
await u.po.expect.toBeSignedIn();
4949
await u.po.userButton.waitForMounted();
5050

51-
await expect(u.page.getByRole('button', { name: /Open user button/i })).toBeVisible();
51+
await expect(u.page.getByRole('button', { name: /Open user menu/i })).toBeVisible();
5252
});
5353

5454
test('user button is functional after sign in', async ({ page, context }) => {

integration/tests/sign-out-smoke.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign out
8484
await u.page.getByRole('link', { name: 'Protected', exact: true }).click();
8585
await u.page.getByTestId('protected').waitFor();
8686
await u.page.getByRole('link', { name: 'Home' }).click();
87-
await u.page.getByRole('button', { name: 'Open user button' }).click();
87+
await u.page.getByRole('button', { name: 'Open user menu' }).click();
8888

8989
await u.page.getByRole('menuitem', { name: 'Sign out' }).click();
9090
await u.page.getByRole('link', { name: 'Protected', exact: true }).click();

integration/tests/user-profile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default function Page() {
127127
await u.page.goToRelative('/');
128128
await u.page.waitForClerkComponentMounted();
129129

130-
await u.page.getByRole('button', { name: 'Open user button' }).click();
130+
await u.page.getByRole('button', { name: 'Open user menu' }).click();
131131

132132
await u.page.getByText(/Manage account/).click();
133133

packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcherTrigger.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useOrganization, useOrganizationList, useUser } from '@clerk/shared/react';
22
import { forwardRef } from 'react';
33

4-
import { OrganizationPreview } from '@/ui/elements/OrganizationPreview';
54
import { PersonalWorkspacePreview } from '@/ui/elements/PersonalWorkspacePreview';
65
import { withAvatarShimmer } from '@/ui/elements/withAvatarShimmer';
76

87
import { NotificationCountBadge, useProtect } from '../../common';
98
import { useEnvironment, useOrganizationSwitcherContext } from '../../contexts';
10-
import { Button, descriptors, Icon, localizationKeys } from '../../customizables';
9+
import { Button, descriptors, Icon, localizationKeys, useLocalizations } from '../../customizables';
1110
import { ChevronDown } from '../../icons';
1211
import type { PropsOfComponent } from '../../styledSystem';
1312
import { organizationListParams } from './utils';
@@ -23,6 +22,7 @@ export const OrganizationSwitcherTrigger = withAvatarShimmer(
2322
const { user } = useUser();
2423
const { organization } = useOrganization();
2524
const { hidePersonal } = useOrganizationSwitcherContext();
25+
const { t } = useLocalizations();
2626

2727
if (!user) {
2828
return null;
@@ -46,20 +46,11 @@ export const OrganizationSwitcherTrigger = withAvatarShimmer(
4646
sx,
4747
]}
4848
ref={ref}
49-
aria-label={`${props.isOpen ? 'Close' : 'Open'} organization switcher`}
49+
aria-label={`${props.isOpen ? t(localizationKeys('organizationSwitcher.action__closeOrganizationSwitcher')) : t(localizationKeys('organizationSwitcher.action__openOrganizationSwitcher'))}`}
5050
aria-expanded={props.isOpen}
5151
aria-haspopup='dialog'
5252
{...rest}
5353
>
54-
{organization && (
55-
<OrganizationPreview
56-
elementId={'organizationSwitcherTrigger'}
57-
gap={3}
58-
size='xs'
59-
organization={organization}
60-
sx={{ maxWidth: '30ch' }}
61-
/>
62-
)}
6354
{!organization && (
6455
<PersonalWorkspacePreview
6556
size='xs'

packages/clerk-js/src/ui/components/UserButton/UserButtonTrigger.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { UserAvatar } from '@/ui/elements/UserAvatar';
55
import { withAvatarShimmer } from '@/ui/elements/withAvatarShimmer';
66

77
import { useUserButtonContext } from '../../contexts';
8-
import { Button, descriptors, Flex } from '../../customizables';
8+
import { Button, descriptors, Flex, localizationKeys, useLocalizations } from '../../customizables';
99
import type { PropsOfComponent } from '../../styledSystem';
1010
import { UserButtonTopLevelIdentifier } from './UserButtonTopLevelIdentifier';
1111

@@ -18,14 +18,15 @@ export const UserButtonTrigger = withAvatarShimmer(
1818
const { sx, ...rest } = props;
1919
const { user } = useUser();
2020
const { showName } = useUserButtonContext();
21+
const { t } = useLocalizations();
2122

2223
return (
2324
<Button
2425
elementDescriptor={descriptors.userButtonTrigger}
2526
variant='roundWrapper'
2627
sx={[t => ({ borderRadius: showName ? t.radii.$md : t.radii.$circle, color: t.colors.$colorForeground }), sx]}
2728
ref={ref}
28-
aria-label={`${props.isOpen ? 'Close' : 'Open'} user button`}
29+
aria-label={`${props.isOpen ? t(localizationKeys('userButton.action__closeUserMenu')) : t(localizationKeys('userButton.action__openUserMenu'))}`}
2930
aria-expanded={props.isOpen}
3031
aria-haspopup='dialog'
3132
{...rest}

packages/clerk-js/src/ui/components/UserButton/__tests__/UserButton.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('UserButton', () => {
3030
__experimental_asStandalone: true,
3131
});
3232
const { getByText, queryByRole } = render(<UserButton />, { wrapper });
33-
expect(queryByRole('button', { name: 'Open user button' })).toBeNull();
33+
expect(queryByRole('button', { name: 'Open user menu' })).toBeNull();
3434
getByText('Manage account');
3535
});
3636

@@ -44,7 +44,7 @@ describe('UserButton', () => {
4444
});
4545
});
4646
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
47-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
47+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
4848
expect(getByText('Manage account')).not.toBeNull();
4949
});
5050

@@ -58,7 +58,7 @@ describe('UserButton', () => {
5858
});
5959
});
6060
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
61-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
61+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
6262
await userEvent.click(getByText('Manage account'));
6363
expect(fixtures.clerk.openUserProfile).toHaveBeenCalled();
6464
});
@@ -76,7 +76,7 @@ describe('UserButton', () => {
7676
fixtures.clerk.signOut.mockImplementationOnce(callback => callback());
7777

7878
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
79-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
79+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
8080
await userEvent.click(getByText('Sign out'));
8181

8282
expect(fixtures.router.navigate).toHaveBeenCalledWith('/');
@@ -96,7 +96,7 @@ describe('UserButton', () => {
9696
props.setProps({ afterSignOutUrl: '/after-sign-out' });
9797

9898
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
99-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
99+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
100100
await userEvent.click(getByText('Sign out'));
101101

102102
expect(fixtures.router.navigate).toHaveBeenCalledWith('/after-sign-out');
@@ -133,7 +133,7 @@ describe('UserButton', () => {
133133
it('renders all sessions', async () => {
134134
const { wrapper } = await createFixtures(initConfig);
135135
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
136-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
136+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
137137
expect(getByText('First1 Last1')).toBeDefined();
138138
expect(getByText('First2 Last2')).toBeDefined();
139139
expect(getByText('First3 Last3')).toBeDefined();
@@ -143,7 +143,7 @@ describe('UserButton', () => {
143143
const { wrapper, fixtures } = await createFixtures(initConfig);
144144
fixtures.clerk.setActive.mockReturnValueOnce(Promise.resolve());
145145
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
146-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
146+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
147147
await userEvent.click(getByText('First3 Last3'));
148148
expect(fixtures.clerk.setActive).toHaveBeenCalledWith(
149149
expect.objectContaining({ session: expect.objectContaining({ user: expect.objectContaining({ id: '3' }) }) }),
@@ -156,7 +156,7 @@ describe('UserButton', () => {
156156
return Promise.resolve(callback());
157157
});
158158
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
159-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
159+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
160160
await userEvent.click(getByText('Sign out'));
161161
await waitFor(() => {
162162
expect(fixtures.clerk.signOut).toHaveBeenCalledWith(expect.any(Function), { sessionId: '0' });
@@ -170,7 +170,7 @@ describe('UserButton', () => {
170170
return Promise.resolve(callback());
171171
});
172172
const { getByText, getByRole, userEvent } = render(<UserButton />, { wrapper });
173-
await userEvent.click(getByRole('button', { name: 'Open user button' }));
173+
await userEvent.click(getByRole('button', { name: 'Open user menu' }));
174174
await userEvent.click(getByText('Sign out of all accounts'));
175175
await waitFor(() => {
176176
expect(fixtures.clerk.signOut).toHaveBeenCalledWith(expect.any(Function));

packages/localizations/src/ar-SA.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,11 @@ export const arSA: LocalizationResource = {
487487
},
488488
},
489489
organizationSwitcher: {
490+
action__closeOrganizationSwitcher: undefined,
490491
action__createOrganization: 'أنشاء منظمة',
491492
action__invitationAccept: 'أنضمام',
492493
action__manageOrganization: 'أدارة المنظمة',
494+
action__openOrganizationSwitcher: undefined,
493495
action__suggestionsAccept: 'طلب أنضمام',
494496
notSelected: 'لم يتم أختيار منظمة',
495497
personalWorkspace: 'الحساب الشخصي',
@@ -938,7 +940,9 @@ export const arSA: LocalizationResource = {
938940
},
939941
userButton: {
940942
action__addAccount: 'إضافة حساب',
943+
action__closeUserMenu: 'إغلاق قائمة المستخدم',
941944
action__manageAccount: 'إدارة الحساب',
945+
action__openUserMenu: 'فتح قائمة المستخدم',
942946
action__signOut: 'تسجيل الخروج',
943947
action__signOutAll: 'تسجيل الخروج من جميع الحسابات',
944948
},

packages/localizations/src/be-BY.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,11 @@ export const beBY: LocalizationResource = {
493493
},
494494
},
495495
organizationSwitcher: {
496+
action__closeOrganizationSwitcher: undefined,
496497
action__createOrganization: 'Стварыць арганізацыю',
497498
action__invitationAccept: 'Join',
498499
action__manageOrganization: 'Кіраванне арганізацыяй',
500+
action__openOrganizationSwitcher: undefined,
499501
action__suggestionsAccept: 'Request to join',
500502
notSelected: 'Арганізацыя не выбрана',
501503
personalWorkspace: 'Асабістае працоўнае прастора',
@@ -947,7 +949,9 @@ export const beBY: LocalizationResource = {
947949
},
948950
userButton: {
949951
action__addAccount: 'Дадаць уліковы запіс',
952+
action__closeUserMenu: undefined,
950953
action__manageAccount: 'Кіраванне ўліковым запісам',
954+
action__openUserMenu: undefined,
951955
action__signOut: 'Выйсці',
952956
action__signOutAll: 'Выйсці з усіх уліковых запісаў',
953957
},

packages/localizations/src/bg-BG.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,11 @@ export const bgBG: LocalizationResource = {
490490
},
491491
},
492492
organizationSwitcher: {
493+
action__closeOrganizationSwitcher: undefined,
493494
action__createOrganization: 'Създаване на организация',
494495
action__invitationAccept: 'Присъединяване',
495496
action__manageOrganization: 'Управление',
497+
action__openOrganizationSwitcher: undefined,
496498
action__suggestionsAccept: 'Заявка за присъединяване',
497499
notSelected: 'Няма избрана организация',
498500
personalWorkspace: 'Личен акаунт',
@@ -939,7 +941,9 @@ export const bgBG: LocalizationResource = {
939941
},
940942
userButton: {
941943
action__addAccount: 'Добавяне на акаунт',
944+
action__closeUserMenu: undefined,
942945
action__manageAccount: 'Управление на акаунта',
946+
action__openUserMenu: undefined,
943947
action__signOut: 'Изход',
944948
action__signOutAll: 'Изход от всички акаунти',
945949
},

0 commit comments

Comments
 (0)