Skip to content

Commit 96af0aa

Browse files
authored
Adds className prop to UnderlineNav component. (#5931)
1 parent c130cc4 commit 96af0aa

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

.changeset/yummy-files-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Adds className prop to UnderlineNav component.

packages/react/src/UnderlineNav/UnderlineNav.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const ResponsiveUnderlineNav = ({
5555

5656
return (
5757
<div>
58-
<UnderlineNav aria-label="Repository" loadingCounters={loadingCounters}>
58+
<UnderlineNav aria-label="Repository" className="foo" loadingCounters={loadingCounters}>
5959
{items.map(item => (
6060
<UnderlineNav.Item
6161
key={item.navigation}
@@ -142,6 +142,12 @@ describe('UnderlineNav', () => {
142142
expect(counter).toHaveAttribute('aria-hidden', 'true')
143143
})
144144

145+
it('adds className prop to base wrapper classes', () => {
146+
const {getByRole} = render(<ResponsiveUnderlineNav />)
147+
const nav = getByRole('navigation')
148+
expect(nav).toHaveAttribute('class', 'UnderlineWrapper foo')
149+
})
150+
145151
it('renders the content of visually hidden span properly for screen readers', () => {
146152
const {getByRole} = render(<ResponsiveUnderlineNav />)
147153
const item = getByRole('link', {name: 'Issues (120)'})

packages/react/src/UnderlineNav/UnderlineNav.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type UnderlineNavProps = {
2626
children: React.ReactNode
2727
'aria-label'?: React.AriaAttributes['aria-label']
2828
as?: React.ElementType
29+
className?: string
2930
sx?: SxProp['sx']
3031
/**
3132
* loading state for all counters. It displays loading animation for individual counters (UnderlineNav.Item) until all are resolved. It is needed to prevent multiple layout shift.
@@ -140,6 +141,7 @@ export const UnderlineNav = forwardRef(
140141
'aria-label': ariaLabel,
141142
sx: sxProp = defaultSxProp,
142143
loadingCounters = false,
144+
className,
143145
children,
144146
}: UnderlineNavProps,
145147
forwardedRef,
@@ -306,7 +308,7 @@ export const UnderlineNav = forwardRef(
306308
}}
307309
>
308310
{ariaLabel && <VisuallyHidden as="h2">{`${ariaLabel} navigation`}</VisuallyHidden>}
309-
<UnderlineWrapper as={as} aria-label={ariaLabel} ref={navRef} sx={sxProp}>
311+
<UnderlineWrapper as={as} aria-label={ariaLabel} className={className} ref={navRef} sx={sxProp}>
310312
<UnderlineItemList ref={listRef} role="list">
311313
{listItems}
312314
{menuItems.length > 0 && (

0 commit comments

Comments
 (0)