Skip to content

Commit

Permalink
[EuiSuperSelect] Fix regenerating and missing IDs (#5197)
Browse files Browse the repository at this point in the history
* Fix regenerating screen reader ID

* Fix undefined input ID
- falls back to a generated ID if passed ID is undefined

* Update snapshots to w/ new superselect ID

* [PR feedback] Remove unnecessary input ID/aria-labelledby association

* Update snapshots
  • Loading branch information
Constance authored Sep 20, 2021
1 parent 571ebc4 commit 17e44b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports[`EuiColorPalettePicker is rendered 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -79,7 +79,7 @@ exports[`EuiColorPalettePicker is rendered with a selected custom text 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -157,7 +157,7 @@ exports[`EuiColorPalettePicker is rendered with a selected fixed palette 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -238,7 +238,7 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette 1`]
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -300,7 +300,7 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette with
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -357,7 +357,7 @@ exports[`EuiColorPalettePicker is rendered with the prop selectionDisplay set as
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -434,7 +434,7 @@ exports[`EuiColorPalettePicker more props are propagated to each option 1`] = `
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelect--isOpen__button"
data-test-subj="colorPalettePicker"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports[`EuiSuperSelect is rendered 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -79,7 +79,7 @@ exports[`EuiSuperSelect props compressed is rendered 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl--compressed testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -130,7 +130,7 @@ exports[`EuiSuperSelect props custom display is propagated to dropdown 1`] = `
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelect--isOpen__button"
data-test-subj="superSelect"
type="button"
Expand Down Expand Up @@ -291,7 +291,7 @@ exports[`EuiSuperSelect props fullWidth is rendered 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl--fullWidth testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -348,7 +348,7 @@ exports[`EuiSuperSelect props is rendered with a prepend and append 1`] = `
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl--inGroup testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -404,7 +404,7 @@ exports[`EuiSuperSelect props more props are propogated to each option 1`] = `
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelect--isOpen__button"
data-test-subj="superSelect"
type="button"
Expand Down Expand Up @@ -569,7 +569,7 @@ exports[`EuiSuperSelect props options are rendered when select is open 1`] = `
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelect--isOpen__button"
data-test-subj="superSelect"
type="button"
Expand Down Expand Up @@ -729,7 +729,7 @@ exports[`EuiSuperSelect props select component is rendered 1`] = `
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl"
type="button"
/>
Expand Down Expand Up @@ -779,7 +779,7 @@ exports[`EuiSuperSelect props valueSelected is rendered 1`] = `
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Array [
<button
aria-haspopup="true"
aria-label="aria-label"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl testClass1 testClass2"
data-test-subj="test subject string"
type="button"
Expand Down Expand Up @@ -64,7 +64,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl--compressed"
type="button"
/>
Expand Down Expand Up @@ -106,7 +106,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl"
type="button"
/>
Expand Down Expand Up @@ -148,7 +148,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl"
type="button"
/>
Expand Down Expand Up @@ -190,7 +190,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl--fullWidth"
type="button"
/>
Expand Down Expand Up @@ -232,7 +232,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl-isInvalid"
type="button"
/>
Expand Down Expand Up @@ -274,7 +274,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl euiSuperSelectControl-isLoading"
type="button"
/>
Expand Down Expand Up @@ -319,7 +319,7 @@ Array [
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
aria-labelledby="generated-id"
class="euiSuperSelectControl"
type="button"
>
Expand Down
6 changes: 3 additions & 3 deletions src/components/form/super_select/super_select_control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import classNames from 'classnames';
import { CommonProps } from '../../common';

import { EuiScreenReaderOnly } from '../../accessibility';
import { htmlIdGenerator } from '../../../services/accessibility';
import { useGeneratedHtmlId } from '../../../services/accessibility';
import {
EuiFormControlLayout,
EuiFormControlLayoutProps,
Expand Down Expand Up @@ -108,7 +108,7 @@ export const EuiSuperSelectControl: <T extends string>(
side: 'right',
};

const screenReaderId = htmlIdGenerator()();
const screenReaderId = useGeneratedHtmlId();

return (
<Fragment>
Expand Down Expand Up @@ -145,7 +145,7 @@ export const EuiSuperSelectControl: <T extends string>(
type="button"
className={classes}
aria-haspopup="true"
aria-labelledby={`${id} ${screenReaderId}`}
aria-labelledby={screenReaderId}
{...rest}
>
{selectedValue}
Expand Down

0 comments on commit 17e44b6

Please sign in to comment.