Skip to content

Commit c2ad5ba

Browse files
committed
Avoid referencing an ID that is not in the DOM
When the menu is not open, do not set the aria props referencing it.
1 parent 2d3d6af commit c2ad5ba

File tree

7 files changed

+9
-12
lines changed

7 files changed

+9
-12
lines changed

.changeset/curly-mice-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-select': minor
3+
---
4+
5+
Avoid referencing an ID that is not in the DOM

packages/react-select/src/Select.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,13 +1558,15 @@ export default class Select<
15581558
'aria-autocomplete': 'list' as const,
15591559
'aria-expanded': menuIsOpen,
15601560
'aria-haspopup': true,
1561-
'aria-controls': this.getElementId('listbox'),
1562-
'aria-owns': this.getElementId('listbox'),
15631561
'aria-errormessage': this.props['aria-errormessage'],
15641562
'aria-invalid': this.props['aria-invalid'],
15651563
'aria-label': this.props['aria-label'],
15661564
'aria-labelledby': this.props['aria-labelledby'],
15671565
role: 'combobox',
1566+
...(menuIsOpen && {
1567+
'aria-controls': this.getElementId('listbox'),
1568+
'aria-owns': this.getElementId('listbox'),
1569+
}),
15681570
...(!isSearchable && {
15691571
'aria-readonly': true,
15701572
}),

packages/react-select/src/__tests__/__snapshots__/Async.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ exports[`defaults - snapshot 1`] = `
193193
>
194194
<input
195195
aria-autocomplete="list"
196-
aria-controls="react-select-2-listbox"
197196
aria-describedby="react-select-2-placeholder"
198197
aria-expanded="false"
199198
aria-haspopup="true"
200-
aria-owns="react-select-2-listbox"
201199
autocapitalize="none"
202200
autocomplete="off"
203201
autocorrect="off"

packages/react-select/src/__tests__/__snapshots__/AsyncCreatable.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ exports[`defaults - snapshot 1`] = `
193193
>
194194
<input
195195
aria-autocomplete="list"
196-
aria-controls="react-select-2-listbox"
197196
aria-describedby="react-select-2-placeholder"
198197
aria-expanded="false"
199198
aria-haspopup="true"
200-
aria-owns="react-select-2-listbox"
201199
autocapitalize="none"
202200
autocomplete="off"
203201
autocorrect="off"

packages/react-select/src/__tests__/__snapshots__/Creatable.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ exports[`defaults - snapshot 1`] = `
193193
>
194194
<input
195195
aria-autocomplete="list"
196-
aria-controls="react-select-2-listbox"
197196
aria-describedby="react-select-2-placeholder"
198197
aria-expanded="false"
199198
aria-haspopup="true"
200-
aria-owns="react-select-2-listbox"
201199
autocapitalize="none"
202200
autocomplete="off"
203201
autocorrect="off"

packages/react-select/src/__tests__/__snapshots__/Select.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ exports[`snapshot - defaults 1`] = `
193193
>
194194
<input
195195
aria-autocomplete="list"
196-
aria-controls="react-select-2-listbox"
197196
aria-describedby="react-select-2-placeholder"
198197
aria-expanded="false"
199198
aria-haspopup="true"
200-
aria-owns="react-select-2-listbox"
201199
autocapitalize="none"
202200
autocomplete="off"
203201
autocorrect="off"

packages/react-select/src/__tests__/__snapshots__/StateManaged.test.tsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ exports[`defaults > snapshot 1`] = `
193193
>
194194
<input
195195
aria-autocomplete="list"
196-
aria-controls="react-select-2-listbox"
197196
aria-describedby="react-select-2-placeholder"
198197
aria-expanded="false"
199198
aria-haspopup="true"
200-
aria-owns="react-select-2-listbox"
201199
autocapitalize="none"
202200
autocomplete="off"
203201
autocorrect="off"

0 commit comments

Comments
 (0)