Skip to content

Commit

Permalink
aria-label improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolinisoup committed Oct 10, 2022
1 parent 4b27d49 commit ed92434
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/content/drafts/UnderlineNav2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {UnderlineNav} from '@primer/react/drafts'
### Simple

```jsx live drafts
<UnderlineNav ariaLabel="Repository">
<UnderlineNav aria-label="Repository">
<UnderlineNav.Item selected>Item 1</UnderlineNav.Item>
<UnderlineNav.Item>Item 2</UnderlineNav.Item>
<UnderlineNav.Item>Item 3</UnderlineNav.Item>
Expand All @@ -26,7 +26,7 @@ import {UnderlineNav} from '@primer/react/drafts'
### With Icons

```jsx live drafts
<UnderlineNav ariaLabel="Repository">
<UnderlineNav aria-label="Repository">
<UnderlineNav.Item selected icon={CodeIcon}>
Code
</UnderlineNav.Item>
Expand All @@ -53,7 +53,7 @@ When overflow occurs, the component first hides icons if present to optimize for
#### Items Without Icons

```jsx live drafts
<UnderlineNav ariaLabel="Repository">
<UnderlineNav aria-label="Repository">
<UnderlineNav.Item selected icon={CodeIcon}>
Code
</UnderlineNav.Item>
Expand Down Expand Up @@ -83,7 +83,7 @@ When overflow occurs, the component first hides icons if present to optimize for
If there is still overflow, the component will behave depending on the pointer.

```jsx live drafts
<UnderlineNav ariaLabel="Repository">
<UnderlineNav aria-label="Repository">
<UnderlineNav.Item selected icon={CodeIcon}>
Code
</UnderlineNav.Item>
Expand Down
11 changes: 8 additions & 3 deletions src/UnderlineNav2/UnderlineNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const UnderlineNav = forwardRef(
{
as = 'nav',
align,
'aria-label': ariaLabel = 'Navigation',
'aria-label': ariaLabel,
sx: sxProp = {},
afterSelect,
variant = 'default',
Expand Down Expand Up @@ -330,6 +330,11 @@ export const UnderlineNav = forwardRef(
focusedLink?.current && isCoarsePointer && scrollLinkIntoView(focusedLink)
}, [focusedLink, isCoarsePointer])

if (!ariaLabel) {
// eslint-disable-next-line no-console
console.warn('Use the `aria-label` prop to provide an accessible label for assistive technology')
}

return (
<UnderlineNavContext.Provider
value={{
Expand Down Expand Up @@ -359,7 +364,7 @@ export const UnderlineNav = forwardRef(
type="left"
show={scrollValues.scrollLeft > 0}
onScrollWithButton={onScrollWithButton}
ariaLabel={ariaLabel}
aria-label={ariaLabel}
/>
)}

Expand Down Expand Up @@ -411,7 +416,7 @@ export const UnderlineNav = forwardRef(
type="right"
show={scrollValues.scrollRight > 0}
onScrollWithButton={onScrollWithButton}
ariaLabel={ariaLabel}
aria-label={ariaLabel}
/>
)}
</Box>
Expand Down
4 changes: 2 additions & 2 deletions src/UnderlineNav2/UnderlineNavArrowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const ArrowButton = ({
type,
show,
onScrollWithButton,
ariaLabel = 'navigation'
'aria-label': ariaLabel
}: {
type: 'left' | 'right'
show: boolean
onScrollWithButton: OnScrollWithButtonEventType
ariaLabel: string
'aria-label'?: React.AriaAttributes['aria-label']
}) => {
const leftBtnRef = React.useRef<HTMLButtonElement>(null)
const rightBtnRef = React.useRef<HTMLButtonElement>(null)
Expand Down

0 comments on commit ed92434

Please sign in to comment.