Skip to content

Commit 98a21bd

Browse files
authored
Merge branch 'main' into siddharthkp/menu-mnemonics
2 parents 7923565 + 40da598 commit 98a21bd

File tree

12 files changed

+29
-40
lines changed

12 files changed

+29
-40
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
AnchoredOverlay accessibility fixes
6+
- `aria-expanded` attribute is removed from anchor when overlay is not open
7+
- `tabIndex=0` is removed from anchor because it should only be used with interactive elements
8+

src/AnchoredOverlay/AnchoredOverlay.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({
165165
ref: anchorRef,
166166
id: anchorId,
167167
'aria-haspopup': 'true',
168-
'aria-expanded': open,
169-
tabIndex: 0,
168+
'aria-expanded': open ? 'true' : undefined,
170169
onClick: onAnchorClick,
171170
onKeyDown: onAnchorKeyDown
172171
})}

src/__tests__/ActionMenu.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('ActionMenu', () => {
108108
<SingleSelection />
109109
</ThemeProvider>
110110
)
111-
const button = component.getByLabelText('Select field type')
111+
const button = component.getByLabelText('Field type')
112112
fireEvent.click(button)
113113

114114
// select first item by role, that would close the menu
@@ -127,7 +127,7 @@ describe('ActionMenu', () => {
127127
<MixedSelection />
128128
</ThemeProvider>
129129
)
130-
const button = component.getByLabelText('Select field type to group by')
130+
const button = component.getByLabelText('Group by')
131131
fireEvent.click(button)
132132

133133
expect(component.getByLabelText('Status')).toHaveAttribute('role', 'menuitemradio')

src/__tests__/__snapshots__/ActionMenu.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,11 @@ exports[`ActionMenu renders consistently 1`] = `
125125
fontFamily="normal"
126126
>
127127
<button
128-
aria-expanded={false}
129128
aria-haspopup="true"
130129
className="c1"
131130
id="react-aria-1"
132131
onClick={[Function]}
133132
onKeyDown={[Function]}
134-
tabIndex={0}
135133
type="button"
136134
>
137135
<span

src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ exports[`AnchoredOverlay renders consistently 1`] = `
8080
fontFamily="normal"
8181
>
8282
<button
83-
aria-expanded={false}
8483
aria-haspopup="true"
8584
className="c1"
8685
id="react-aria-1"
8786
onClick={[Function]}
8887
onKeyDown={[Function]}
89-
tabIndex={0}
9088
>
9189
Anchor Button
9290
</button>
@@ -203,7 +201,6 @@ exports[`AnchoredOverlay should render consistently when open 1`] = `
203201
aria-haspopup="true"
204202
class="c1"
205203
id="react-aria-1"
206-
tabindex="0"
207204
>
208205
Anchor Button
209206
</button>

src/__tests__/__snapshots__/SelectPanel.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,11 @@ exports[`SelectPanel renders consistently 1`] = `
8484
fontFamily="normal"
8585
>
8686
<button
87-
aria-expanded={false}
8887
aria-haspopup="true"
8988
className="c1"
9089
id="react-aria-1"
9190
onClick={[Function]}
9291
onKeyDown={[Function]}
93-
tabIndex={0}
9492
type="button"
9593
>
9694
Select Items

src/__tests__/deprecated/__snapshots__/ActionMenu.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ exports[`ActionMenu renders consistently 1`] = `
6868
}
6969
7070
<button
71-
aria-expanded={false}
7271
aria-haspopup="true"
7372
aria-label="menu"
7473
className="c0"
7574
id="react-aria-1"
7675
onClick={[Function]}
7776
onKeyDown={[Function]}
78-
tabIndex={0}
7977
/>
8078
`;

src/__tests__/deprecated/__snapshots__/DropdownMenu.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ exports[`DropdownMenu renders consistently 1`] = `
7272
}
7373
7474
<button
75-
aria-expanded={false}
7675
aria-haspopup="true"
7776
className="c0"
7877
id="react-aria-1"
7978
onClick={[Function]}
8079
onKeyDown={[Function]}
81-
tabIndex={0}
8280
type="button"
8381
>
8482
<svg

src/stories/ActionList/examples.stories.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function MultipleSelection(): JSX.Element {
156156

157157
<p>This pattern appears in issues and pull requests to pick multiple assignees</p>
158158

159-
<ActionList selectionVariant="multiple" showDividers role="listbox" aria-label="Select assignees">
159+
<ActionList selectionVariant="multiple" showDividers role="listbox" aria-label="Assignees">
160160
{users.map(user => (
161161
<ActionList.Item
162162
role="option"
@@ -192,7 +192,7 @@ export function Groups(): JSX.Element {
192192

193193
<p>Grouped content with labels and description. This patterns appears in pull requests to pick a reviewer.</p>
194194

195-
<ActionList selectionVariant="multiple" role="menu" showDividers aria-label="Select reviewers">
195+
<ActionList selectionVariant="multiple" role="menu" showDividers aria-label="Reviewers">
196196
<ActionList.Group title="Suggestions">
197197
{users.slice(0, 2).map(user => (
198198
<ActionList.Item
@@ -328,12 +328,7 @@ export function AsyncListWithSpinner(): JSX.Element {
328328
{results.length === 0 ? (
329329
<Text sx={{display: 'block', fontSize: 1, m: 2}}>No branches match that query</Text>
330330
) : null}
331-
<ActionList
332-
selectionVariant="single"
333-
role="listbox"
334-
aria-label="Select a branch"
335-
sx={{height: 208, overflow: 'auto'}}
336-
>
331+
<ActionList selectionVariant="single" role="listbox" aria-label="Branch" sx={{height: 208, overflow: 'auto'}}>
337332
{loading ? (
338333
<Box sx={{display: 'flex', justifyContent: 'center', pt: 2}}>
339334
<Spinner />

src/stories/ActionList/fixtures.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export function DisabledStory(): JSX.Element {
208208
<>
209209
<h1>Disabled Items</h1>
210210
<ErsatzOverlay>
211-
<ActionList selectionVariant="single" showDividers role="menu" aria-label="Select a project">
211+
<ActionList selectionVariant="single" showDividers role="menu" aria-label="Project">
212212
{projects.map((project, index) => (
213213
<ActionList.Item
214214
key={index}
@@ -836,7 +836,7 @@ export function ChildWithSideEffects(): JSX.Element {
836836
<>
837837
<h1>Child with side effects</h1>
838838
<ErsatzOverlay>
839-
<ActionList selectionVariant="multiple" role="listbox" aria-label="Select assignees">
839+
<ActionList selectionVariant="multiple" role="listbox" aria-label="Assignees">
840840
<ActionList.Item selected={selected} onSelect={() => setSelected(!selected)} role="option">
841841
<ActionList.LeadingVisual>
842842
<Avatar src={`https://avatars.githubusercontent.com/${user.login}`} />

0 commit comments

Comments
 (0)