Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ActionList): place id on item with role #3691

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions .changeset/giant-bobcats-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

Update ActionList to place `id` on item with an ARIA role

<!-- Changed components: ActionList -->
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
[onSelect, disabled, afterSelect],
)

// use props.id if provided, otherwise generate one.
const labelId = useId(id)
const inlineDescriptionId = useId(id && `${id}--inline-description`)
const blockDescriptionId = useId(id && `${id}--block-description`)
const itemId = useId(id)
const labelId = `${itemId}--label`
const inlineDescriptionId = `${itemId}--inline-description`
const blockDescriptionId = `${itemId}--block-description`

const ItemWrapper = _PrivateItemWrapper || React.Fragment

Expand All @@ -201,6 +201,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
'aria-describedby': slots.description?.props.variant === 'block' ? blockDescriptionId : undefined,
...(selectionAttribute && {[selectionAttribute]: selected}),
role: role || itemRole,
id: itemId,
}

const containerProps = _PrivateItemWrapper ? {role: role || itemRole ? 'none' : undefined} : menuItemProps
Expand Down
49 changes: 29 additions & 20 deletions src/NavList/__snapshots__/NavList.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ exports[`NavList renders a simple list 1`] = `
>
<a
aria-current="page"
aria-labelledby="react-aria-1 "
aria-labelledby="react-aria-1--label "
class="c3"
href="/"
id="react-aria-1"
tabindex="0"
>
<div
Expand All @@ -315,7 +316,7 @@ exports[`NavList renders a simple list 1`] = `
>
<span
class="c5"
id="react-aria-1"
id="react-aria-1--label"
>
Home
</span>
Expand All @@ -326,9 +327,10 @@ exports[`NavList renders a simple list 1`] = `
class="c1 c6"
>
<a
aria-labelledby="react-aria-4 "
aria-labelledby="react-aria-2--label "
class="c3"
href="/about"
id="react-aria-2"
tabindex="0"
>
<div
Expand All @@ -337,7 +339,7 @@ exports[`NavList renders a simple list 1`] = `
>
<span
class="c5"
id="react-aria-4"
id="react-aria-2--label"
>
About
</span>
Expand All @@ -348,9 +350,10 @@ exports[`NavList renders a simple list 1`] = `
class="c1 c6"
>
<a
aria-labelledby="react-aria-7 "
aria-labelledby="react-aria-3--label "
class="c3"
href="/contact"
id="react-aria-3"
tabindex="0"
>
<div
Expand All @@ -359,7 +362,7 @@ exports[`NavList renders a simple list 1`] = `
>
<span
class="c5"
id="react-aria-7"
id="react-aria-3--label"
>
Contact
</span>
Expand Down Expand Up @@ -732,9 +735,10 @@ exports[`NavList renders with groups 1`] = `
>
<a
aria-current="page"
aria-labelledby="react-aria-2 "
aria-labelledby="react-aria-2--label "
class="c7"
href="/getting-started"
id="react-aria-2"
tabindex="0"
>
<div
Expand All @@ -743,7 +747,7 @@ exports[`NavList renders with groups 1`] = `
>
<span
class="c9"
id="react-aria-2"
id="react-aria-2--label"
>
Getting started
</span>
Expand All @@ -766,22 +770,23 @@ exports[`NavList renders with groups 1`] = `
role="presentation"
>
<span
id="react-aria-5"
id="react-aria-3"
>
Components
</span>
</div>
<ul
aria-labelledby="react-aria-5"
aria-labelledby="react-aria-3"
class="c4"
>
<li
class="c5 c10"
>
<a
aria-labelledby="react-aria-6 "
aria-labelledby="react-aria-4--label "
class="c7"
href="/Avatar"
id="react-aria-4"
tabindex="0"
>
<div
Expand All @@ -790,7 +795,7 @@ exports[`NavList renders with groups 1`] = `
>
<span
class="c9"
id="react-aria-6"
id="react-aria-4--label"
>
Avatar
</span>
Expand Down Expand Up @@ -1194,8 +1199,9 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
<button
aria-controls="react-aria-2"
aria-expanded="true"
aria-labelledby="react-aria-1 "
aria-labelledby="react-aria-1--label "
class="c2 c3"
id="react-aria-1"
tabindex="0"
>
<div
Expand All @@ -1207,7 +1213,7 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
>
<span
class="c6"
id="react-aria-1"
id="react-aria-1--label"
>
Item
</span>
Expand Down Expand Up @@ -1244,9 +1250,10 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
>
<a
aria-current="page"
aria-labelledby="react-aria-3 "
aria-labelledby="react-aria-3--label "
class="c11"
href="#"
id="react-aria-3"
tabindex="0"
>
<div
Expand All @@ -1255,7 +1262,7 @@ exports[`NavList.Item with NavList.SubNav does not have active styles if SubNav
>
<span
class="c6"
id="react-aria-3"
id="react-aria-3--label"
>
Sub Item
</span>
Expand Down Expand Up @@ -1672,8 +1679,9 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
<button
aria-controls="react-aria-2"
aria-expanded="false"
aria-labelledby="react-aria-1 "
aria-labelledby="react-aria-1--label "
class="c2 c3"
id="react-aria-1"
tabindex="0"
>
<div
Expand All @@ -1685,7 +1693,7 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
>
<span
class="c6"
id="react-aria-1"
id="react-aria-1--label"
>
Item
</span>
Expand Down Expand Up @@ -1722,9 +1730,10 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
>
<a
aria-current="page"
aria-labelledby="react-aria-3 "
aria-labelledby="react-aria-3--label "
class="c11"
href="#"
id="react-aria-3"
tabindex="0"
>
<div
Expand All @@ -1733,7 +1742,7 @@ exports[`NavList.Item with NavList.SubNav has active styles if SubNav contains t
>
<span
class="c6"
id="react-aria-3"
id="react-aria-3--label"
>
Sub Item
</span>
Expand Down
4 changes: 2 additions & 2 deletions src/drafts/InlineAutocomplete/InlineAutocomplete.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useLayoutEffect, useState} from 'react'
import {fireEvent, render, within} from '@testing-library/react'
import {fireEvent, render, within, screen} from '@testing-library/react'

Check failure on line 2 in src/drafts/InlineAutocomplete/InlineAutocomplete.test.tsx

View workflow job for this annotation

GitHub Actions / lint

'screen' is defined but never used
import userEvent from '@testing-library/user-event'
import InlineAutocomplete, {ShowSuggestionsEvent, Suggestions, Trigger} from '.'
import FormControl from '../../FormControl'
Expand Down Expand Up @@ -361,7 +361,7 @@
await user.keyboard('{ArrowDown}')

expect(input).toHaveFocus()
expect(input).toHaveAttribute('aria-activedescendant', expect.stringContaining('option-1'))
expect(input).toHaveAttribute('aria-activedescendant', 'github')
expect(within(getByRole('listbox')).queryAllByRole('option')[1]).toHaveAttribute('aria-selected', 'true')

await user.keyboard('{Enter}')
Expand Down
Loading