Skip to content

Commit a2eada9

Browse files
committed
Added variant prop to SubNav.Link
1 parent 8223135 commit a2eada9

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

.changeset/slimy-snakes-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
`SubNav.Link` now supports `variant="default"` to help increase text contrast and legibility with non-standard backgrounds.

apps/docs/content/components/SubNav.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ Submenus appear as a dropdown by default.
129129

130130
### SubNav.Link <Label>Required</Label>
131131

132-
| name | type | default | required | description |
133-
| -------------- | -------- | ------- | -------- | ----------------------------------------------- |
134-
| `aria-current` | `string` | | `true` | Required for indicating the current active link |
135-
| `href` | `string` | | `true` | URL of the page the link goes to |
132+
| name | type | default | required | description |
133+
| -------------- | --------------------------------------------------------------- | ------- | -------- | -------------------------------------------------------------------- |
134+
| `aria-current` | `string` | | `true` | Required for indicating the current active link |
135+
| `href` | `string` | | `true` | URL of the page the link goes to |
136+
| `variant` | <PropTableValues values={['default', 'muted']} addLineBreaks /> | `muted` | `false` | Alternative idle text appearance. Recommended for improving contrast |
136137

137138
### SubNav.Action
138139

packages/react/src/SubNav/SubNav.features.stories.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,28 @@ NarrowAnchorNavVariantMenuOpen.play = async ({canvasElement}) => {
235235
const firstLink = within(overlayMenu).getAllByRole('link')[0]
236236
expect(firstLink).toHaveFocus()
237237
}
238+
239+
export const AnchorNavDefaultLinkVariant = args => (
240+
<SubNav {...args}>
241+
<SubNav.Heading href="#">Heading</SubNav.Heading>
242+
<SubNav.Link href="#" variant="default">
243+
Link
244+
</SubNav.Link>
245+
<SubNav.Link href="#" variant="default">
246+
Link
247+
</SubNav.Link>
248+
<SubNav.Link href="#" variant="default">
249+
Link
250+
</SubNav.Link>
251+
<SubNav.Link href="#" variant="default">
252+
Link
253+
</SubNav.Link>
254+
<SubNav.Link href="#" variant="default">
255+
Link
256+
</SubNav.Link>
257+
<SubNav.Link href="#" variant="default">
258+
Link
259+
</SubNav.Link>
260+
<SubNav.Action href="#">Primary CTA</SubNav.Action>
261+
</SubNav>
262+
)

packages/react/src/SubNav/SubNav.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import React, {
1515
type ReactNode,
1616
type RefObject,
1717
} from 'react'
18-
import {Button, ButtonSizes, ButtonVariants, Text, ThemeProvider, useWindowSize} from '..'
18+
import {Button, ButtonSizes, ButtonVariants, Text, TextProps, ThemeProvider, useWindowSize} from '..'
1919

2020
import {default as clsx} from 'clsx'
2121
import {ChevronDownIcon, ChevronUpIcon} from '@primer/octicons-react'
@@ -341,13 +341,14 @@ const SubNavHeading = ({href, children, className, 'data-testid': testID, ...pro
341341
type SubNavLinkProps = {
342342
href: string
343343
'data-testid'?: string
344-
_variant?: SubMenuVariants
344+
variant?: TextProps['variant']
345+
_subMenuVariant?: SubMenuVariants
345346
} & PropsWithChildren<React.HTMLProps<HTMLAnchorElement>> &
346347
BaseProps<HTMLAnchorElement>
347348

348349
const SubNavLinkWithSubmenu = forwardRef<HTMLDivElement, SubNavLinkProps>(
349350
(
350-
{children, href, 'aria-current': ariaCurrent, 'data-testid': testId, className, _variant, ...props},
351+
{children, href, 'aria-current': ariaCurrent, 'data-testid': testId, className, _subMenuVariant, variant, ...props},
351352
forwardedRef,
352353
) => {
353354
const submenuId = useId()
@@ -397,7 +398,7 @@ const SubNavLinkWithSubmenu = forwardRef<HTMLDivElement, SubNavLinkProps>(
397398
size="200"
398399
weight="semibold"
399400
className={styles['SubNav__link-label']}
400-
variant={ariaCurrent === 'page' ? 'default' : 'muted'}
401+
variant={ariaCurrent === 'page' || variant === 'default' ? 'default' : 'muted'}
401402
>
402403
{label}
403404
</Text>
@@ -462,13 +463,13 @@ const SubNavLink = forwardRef<HTMLAnchorElement | HTMLDivElement, SubNavLinkProp
462463
<SubNavLinkWithSubmenu
463464
{...props}
464465
ref={ref as RefObject<HTMLDivElement>}
465-
_variant={isAnchorVariantSubMenu ? 'anchor' : undefined}
466+
_subMenuVariant={isAnchorVariantSubMenu ? 'anchor' : undefined}
466467
/>
467468
</li>
468469
)
469470
}
470471

471-
const {children, href, 'aria-current': ariaCurrent, 'data-testid': testId, className, ...rest} = props
472+
const {children, href, 'aria-current': ariaCurrent, 'data-testid': testId, variant, className, ...rest} = props
472473

473474
return (
474475
<li>
@@ -490,7 +491,7 @@ const SubNavLink = forwardRef<HTMLAnchorElement | HTMLDivElement, SubNavLinkProp
490491
size="100"
491492
weight="semibold"
492493
className={styles['SubNav__link-label']}
493-
variant={ariaCurrent === 'page' ? 'default' : 'muted'}
494+
variant={ariaCurrent === 'page' || variant === 'default' ? 'default' : 'muted'}
494495
>
495496
{children}
496497
</Text>

packages/react/src/SubNav/SubNav.visual.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,12 @@ test.describe('Visual Comparison: SubNav', () => {
117117
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
118118
})
119119
})
120+
test('SubNav / Anchor Nav Default Link Variant', async ({page}) => {
121+
await page.goto(
122+
'http://localhost:6006/iframe.html?args=&id=components-subnav-features--anchor-nav-default-link-variant&viewMode=story',
123+
)
124+
125+
await page.waitForTimeout(500)
126+
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
127+
})
120128
})
Loading

0 commit comments

Comments
 (0)