Skip to content

Commit 1a15bac

Browse files
CopilotjonrohanfrancineluccaCopilot
authored
Add className support to UnderlineNav.Item component (#6129)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com> Co-authored-by: Jon Rohan <yes@jonrohan.codes> Co-authored-by: Marie Lucca <40550942+francinelucca@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 41b4bdb commit 1a15bac

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.changeset/strange-lions-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
UnderlineNav.Item accepts className prop without overriding existing styling

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ describe('UnderlineNav', () => {
197197
expect(screen.getByLabelText('Page two icon')).toBeInTheDocument()
198198
expect(screen.getByLabelText('Page three icon')).toBeInTheDocument()
199199
})
200+
201+
it('adds className prop to item classes', () => {
202+
render(
203+
<UnderlineNav aria-label="Repository">
204+
<UnderlineNav.Item className="custom-class">Item 1</UnderlineNav.Item>
205+
</UnderlineNav>,
206+
)
207+
const item = screen.getByRole('link', {name: 'Item 1'})
208+
expect(item).toHaveClass('custom-class')
209+
expect(item.className).toContain('UnderlineItem')
210+
})
200211
})
201212

202213
describe('Keyboard Navigation', () => {

packages/react/src/internal/components/UnderlineTabbedInterface.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,19 @@ export const UnderlineItem = forwardRef(
101101
iconsVisible,
102102
loadingCounters,
103103
sx: sxProp = defaultSxProp,
104+
className,
104105
...rest
105106
}: PropsWithChildren<UnderlineItemProps>,
106107
forwardedRef,
107108
) => {
108109
return (
109-
<BoxWithFallback ref={forwardedRef} as={as} sx={sxProp} className={classes.UnderlineItem} {...rest}>
110+
<BoxWithFallback
111+
ref={forwardedRef}
112+
as={as}
113+
sx={sxProp}
114+
className={clsx(classes.UnderlineItem, className)}
115+
{...rest}
116+
>
110117
{iconsVisible && Icon && <span data-component="icon">{isElement(Icon) ? Icon : <Icon />}</span>}
111118
{children && (
112119
<span data-component="text" data-content={children}>

0 commit comments

Comments
 (0)