Skip to content

Commit

Permalink
Avoid referencing an ID that is not in the DOM (#5131)
Browse files Browse the repository at this point in the history
When the menu is not open, do not set the aria props
referencing it.

Co-authored-by: Nathan Bierema <nbierema@gmail.com>
  • Loading branch information
pcorpet and Methuselah96 authored Apr 10, 2022
1 parent c7d8d4b commit 87e1443
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-mice-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-select': patch
---

Avoid referencing an ID that is not in the DOM
6 changes: 4 additions & 2 deletions packages/react-select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1560,13 +1560,15 @@ export default class Select<
'aria-autocomplete': 'list' as const,
'aria-expanded': menuIsOpen,
'aria-haspopup': true,
'aria-controls': this.getElementId('listbox'),
'aria-owns': this.getElementId('listbox'),
'aria-errormessage': this.props['aria-errormessage'],
'aria-invalid': this.props['aria-invalid'],
'aria-label': this.props['aria-label'],
'aria-labelledby': this.props['aria-labelledby'],
role: 'combobox',
...(menuIsOpen && {
'aria-controls': this.getElementId('listbox'),
'aria-owns': this.getElementId('listbox'),
}),
...(!isSearchable && {
'aria-readonly': true,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ exports[`defaults - snapshot 1`] = `
>
<input
aria-autocomplete="list"
aria-controls="react-select-2-listbox"
aria-describedby="react-select-2-placeholder"
aria-expanded="false"
aria-haspopup="true"
aria-owns="react-select-2-listbox"
autocapitalize="none"
autocomplete="off"
autocorrect="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ exports[`defaults - snapshot 1`] = `
>
<input
aria-autocomplete="list"
aria-controls="react-select-2-listbox"
aria-describedby="react-select-2-placeholder"
aria-expanded="false"
aria-haspopup="true"
aria-owns="react-select-2-listbox"
autocapitalize="none"
autocomplete="off"
autocorrect="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ exports[`defaults - snapshot 1`] = `
>
<input
aria-autocomplete="list"
aria-controls="react-select-2-listbox"
aria-describedby="react-select-2-placeholder"
aria-expanded="false"
aria-haspopup="true"
aria-owns="react-select-2-listbox"
autocapitalize="none"
autocomplete="off"
autocorrect="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ exports[`snapshot - defaults 1`] = `
>
<input
aria-autocomplete="list"
aria-controls="react-select-2-listbox"
aria-describedby="react-select-2-placeholder"
aria-expanded="false"
aria-haspopup="true"
aria-owns="react-select-2-listbox"
autocapitalize="none"
autocomplete="off"
autocorrect="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ exports[`defaults > snapshot 1`] = `
>
<input
aria-autocomplete="list"
aria-controls="react-select-2-listbox"
aria-describedby="react-select-2-placeholder"
aria-expanded="false"
aria-haspopup="true"
aria-owns="react-select-2-listbox"
autocapitalize="none"
autocomplete="off"
autocorrect="off"
Expand Down

0 comments on commit 87e1443

Please sign in to comment.