Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/young-deers-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Introduce the `navbarButtonText` element descriptor.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ describe('UserProfile', () => {
});

render(<UserProfile />, { wrapper });
const profileElements = screen.getAllByText(/Profile/i);
expect(profileElements.some(el => el.tagName.toUpperCase() === 'BUTTON')).toBe(true);
const securityElements = screen.getAllByText(/Security/i);
expect(securityElements.some(el => el.tagName.toUpperCase() === 'BUTTON')).toBe(true);
const profileElements = screen.getAllByRole('button', { name: /Profile/i });
expect(profileElements.length).toBeGreaterThan(0);
const securityElements = screen.getAllByRole('button', { name: /Security/i });
expect(securityElements.length).toBeGreaterThan(0);
});

it('includes custom nav items', async () => {
Expand All @@ -45,14 +45,14 @@ describe('UserProfile', () => {

props.setProps({ customPages });
render(<UserProfile />, { wrapper });
const profileElements = screen.getAllByText(/Profile/i);
expect(profileElements.some(el => el.tagName.toUpperCase() === 'BUTTON')).toBe(true);
const securityElements = screen.getAllByText(/Security/i);
expect(securityElements.some(el => el.tagName.toUpperCase() === 'BUTTON')).toBe(true);
const customElements = screen.getAllByText(/Custom1/i);
expect(customElements.some(el => el.tagName.toUpperCase() === 'BUTTON')).toBe(true);
const externalElements = screen.getAllByText(/ExternalLink/i);
expect(externalElements.some(el => el.tagName.toUpperCase() === 'BUTTON')).toBe(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const profileElements = screen.getAllByRole('button', { name: /Profile/i });
expect(profileElements.length).toBeGreaterThan(0);
const securityElements = screen.getAllByRole('button', { name: /Security/i });
expect(securityElements.length).toBeGreaterThan(0);
const customElements = screen.getAllByRole('button', { name: /Custom1/i });
expect(customElements.length).toBeGreaterThan(0);
const externalElements = screen.getAllByRole('button', { name: /ExternalLink/i });
expect(externalElements.length).toBeGreaterThan(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const APPEARANCE_KEYS = containsAllElementsConfigKeys([
'navbarButtons',
'navbarButton',
'navbarButtonIcon',
'navbarButtonText',
'navbarMobileMenuRow',
'navbarMobileMenuButton',
'navbarMobileMenuButtonIcon',
Expand Down
2 changes: 2 additions & 0 deletions packages/clerk-js/src/ui/customizables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ export const Tbody = makeCustomizable(sanitizeDomProps(Primitives.Tbody));
export const Tr = makeCustomizable(sanitizeDomProps(Primitives.Tr));
export const Th = makeCustomizable(makeLocalizable(sanitizeDomProps(Primitives.Th)));
export const Td = makeCustomizable(makeLocalizable(sanitizeDomProps(Primitives.Td)));

export const Span = makeCustomizable(makeLocalizable(sanitizeDomProps(Primitives.Span)));
9 changes: 6 additions & 3 deletions packages/clerk-js/src/ui/elements/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContextAndHook } from '@clerk/shared/react';
import React, { useCallback } from 'react';

import type { LocalizationKey } from '../customizables';
import { Button, Col, descriptors, Flex, Heading, Icon, Text, useLocalizations } from '../customizables';
import { Button, Col, descriptors, Flex, Heading, Icon, Span, Text, useLocalizations } from '../customizables';
import type { ElementDescriptor, ElementId } from '../customizables/elementDescriptors';
import { useNavigateToFlowStart, usePopover } from '../hooks';
import { Menu } from '../icons';
Expand Down Expand Up @@ -47,7 +47,6 @@ export const NavBar = (props: NavBarProps) => {
const { close } = useNavbarContext();
const { navigate } = useRouter();
const { navigateToFlowStart } = useNavigateToFlowStart();
const { t } = useLocalizations();
const router = useRouter();

const handleNavigate = (route: NavbarRoute) => {
Expand Down Expand Up @@ -105,7 +104,11 @@ export const NavBar = (props: NavBarProps) => {
minHeight: t.space.$8,
})}
>
{t(r.name)}
<Span
elementDescriptor={descriptors.navbarButtonText}
elementId={descriptors.navbarButtonText.setId(r.id as any)}
localizationKey={r.name}
/>
Comment on lines +107 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Could this be replaced with <Text as="span"/> ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because of the default styles the <Text /> component applies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

</NavButton>
))}
</Col>
Expand Down
13 changes: 13 additions & 0 deletions packages/clerk-js/src/ui/primitives/Span.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

export const Span = React.forwardRef<
HTMLSpanElement,
React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
>((props, ref) => {
return (
<span
{...props}
ref={ref}
/>
);
});
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/primitives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './Tr';
export * from './Th';
export * from './Td';
export * from './NotificationBadge';
export * from './Span';
1 change: 1 addition & 0 deletions packages/types/src/appearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export type ElementsConfig = {
navbarButtons: WithOptions<never, ActiveState>;
navbarButton: WithOptions<string, ActiveState>;
navbarButtonIcon: WithOptions<string, ActiveState>;
navbarButtonText: WithOptions<string, ActiveState>;
navbarMobileMenuRow: WithOptions;
navbarMobileMenuButton: WithOptions;
navbarMobileMenuButtonIcon: WithOptions;
Expand Down
Loading