Skip to content

Commit

Permalink
Avoid referencing an ID that is not in the DOM
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.
  • Loading branch information
pcorpet authored and Rall3n committed Apr 10, 2022
1 parent 09f12f6 commit 87437cb
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
@@ -0,0 +1,5 @@
---
'react-select': minor
---

Avoid referencing an ID that is not in the DOM
6 changes: 4 additions & 2 deletions packages/react-select/src/Select.tsx
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
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
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
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
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
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 87437cb

Please sign in to comment.