Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiSuperSelect] Adding generated IDs to create accessible label and description #5364

Merged
merged 11 commits into from
Nov 17, 2021
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Fixed an `EuiDataGrid` race condition where grid rows had incorrect heights if loaded in before CSS ([#5284](https://github.com/elastic/eui/pull/5284))
- Fixed an accessibility issue where `EuiDataGrid` cells weren't owned by `role=row` elements ([#5285](https://github.com/elastic/eui/pull/5285))
- Fixed an accessibility issue where `EuiSuperSelect` was not creating accessible labels for its listbox ([#5364](https://github.com/elastic/eui/pull/5364))
- Fixed an accessibility issue where `EuiColorPalettePicker` was not creating an accessible label for its button ([#5364](https://github.com/elastic/eui/pull/5364))
- Fixed `EuiErrorBoundary` overflow scrolling by wrapping contents in `EuiCodeBlock` ([#5359](https://github.com/elastic/eui/pull/5359))

## [`41.0.0`](https://github.com/elastic/eui/tree/v41.0.0)
Expand Down
14 changes: 9 additions & 5 deletions src-docs/src/views/form_compressed/complex_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export default () => {
},
];

const superSelectOptions = [
{ value: 'option_one', inputDisplay: 'Option one' },
{ value: 'option_two', inputDisplay: 'Option two' },
{ value: 'option_three', inputDisplay: 'Option three' },
];

const selectTooltipContent =
'Otherwise use an EuiToolTip around the label of the form row.';

Expand All @@ -112,6 +118,7 @@ export default () => {
granularityToggleButtonsIdSelected,
setGranularityToggleButtonsIdSelected,
] = useState(granularityToggleButtonId__2);
const [superSelectValue] = useState(superSelectOptions[0].value);

const onPopoverSliderValueChange = (e) => {
setPopoverSliderValues(e.target.value);
Expand Down Expand Up @@ -241,11 +248,8 @@ export default () => {

<EuiFormRow label="Select one" display="columnCompressed">
<EuiSuperSelect
options={[
{ value: 'option_one', inputDisplay: 'Option one' },
{ value: 'option_two', inputDisplay: 'Option two' },
{ value: 'option_three', inputDisplay: 'Option three' },
]}
options={superSelectOptions}
valueOfSelected={superSelectValue}
compressed
/>
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports[`EuiColorPaletteDisplay is rendered 1`] = `
data-test-subj="test subject string"
>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand Down Expand Up @@ -34,9 +35,14 @@ exports[`EuiColorPaletteDisplay props HTML attributes accepts span attributes 1`
class="euiColorPaletteDisplay testClass1 testClass2 euiColorPaletteDisplay--sizeSmall"
data-test-subj="test subject string"
id="id"
title="title"
>
<span
class="euiScreenReaderOnly"
>
title
</span>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand Down Expand Up @@ -65,6 +71,7 @@ exports[`EuiColorPaletteDisplay props size m is rendered 1`] = `
data-test-subj="test subject string"
>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand Down Expand Up @@ -93,6 +100,7 @@ exports[`EuiColorPaletteDisplay props size s is rendered 1`] = `
data-test-subj="test subject string"
>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand Down Expand Up @@ -121,6 +129,7 @@ exports[`EuiColorPaletteDisplay props size xs is rendered 1`] = `
data-test-subj="test subject string"
>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand Down Expand Up @@ -149,6 +158,7 @@ exports[`EuiColorPaletteDisplay props type and palette are rendered with type fi
data-test-subj="test subject string"
>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand All @@ -174,6 +184,7 @@ exports[`EuiColorPaletteDisplay props type and palette are rendered with type fi
data-test-subj="test subject string"
>
<span
aria-hidden="true"
class="euiColorPaletteDisplayFixed__bleedArea"
>
<span
Expand All @@ -197,6 +208,7 @@ exports[`EuiColorPaletteDisplay props type and palette are rendered with type fi

exports[`EuiColorPaletteDisplay props type and palette are rendered with type gradient and palette with stops 1`] = `
<span
aria-hidden="true"
aria-label="aria-label"
class="euiColorPaletteDisplay testClass1 testClass2 euiColorPaletteDisplay--sizeSmall"
data-test-subj="test subject string"
Expand All @@ -206,6 +218,7 @@ exports[`EuiColorPaletteDisplay props type and palette are rendered with type gr

exports[`EuiColorPaletteDisplay props type and palette are rendered with type gradient and palette without stops 1`] = `
<span
aria-hidden="true"
aria-label="aria-label"
class="euiColorPaletteDisplay testClass1 testClass2 euiColorPaletteDisplay--sizeSmall"
data-test-subj="test subject string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import { CommonProps } from '../../common';
import { getFixedLinearGradient } from '../utils';
import { EuiScreenReaderOnly } from '../../accessibility/screen_reader';
import { EuiColorPaletteDisplayShared } from './color_palette_display';

export interface EuiColorPaletteDisplayFixedProps
Expand All @@ -23,6 +24,7 @@ interface paletteItem {

export const EuiColorPaletteDisplayFixed: FunctionComponent<EuiColorPaletteDisplayFixedProps> = ({
palette,
title,
...rest
}) => {
const fixedGradient = getFixedLinearGradient(palette);
Expand All @@ -36,7 +38,17 @@ export const EuiColorPaletteDisplayFixed: FunctionComponent<EuiColorPaletteDispl

return (
<span {...rest}>
<span className="euiColorPaletteDisplayFixed__bleedArea">
{title && (
<EuiScreenReaderOnly>
<span>{title}</span>
</EuiScreenReaderOnly>
)}
<span
// aria-hidden="true" is to ensure color blocks are ignored by screen readers,
// and the only accessible text for options is the EuiScreenReaderOnly {title}
aria-hidden="true"
Copy link
Contributor Author

@1Copenut 1Copenut Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This aria-hidden="true" is to ensure the color blocks are ignored by screen readers, and the only accessible text for options is the title string.

className="euiColorPaletteDisplayFixed__bleedArea"
>
{paletteStops}
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import { CommonProps } from '../../common';
import { getLinearGradient } from '../utils';
import { EuiScreenReaderOnly } from '../../accessibility/screen_reader';
import { EuiColorPaletteDisplayShared } from './color_palette_display';

export interface EuiColorPaletteDisplayGradientProps
Expand All @@ -18,10 +19,26 @@ export interface EuiColorPaletteDisplayGradientProps

export const EuiColorPaletteDisplayGradient: FunctionComponent<EuiColorPaletteDisplayGradientProps> = ({
palette,
title,
style = {},
...rest
}) => {
const gradient = getLinearGradient(palette);

return <span style={{ ...style, background: gradient }} {...rest} />;
return (
<>
{title && (
<EuiScreenReaderOnly>
<span>{title}</span>
</EuiScreenReaderOnly>
)}
<span
// aria-hidden="true" is to ensure color blocks are ignored by screen readers,
// and the only accessible text for options is the EuiScreenReaderOnly {title}
aria-hidden="true"
1Copenut marked this conversation as resolved.
Show resolved Hide resolved
style={{ ...style, background: gradient }}
{...rest}
/>
</>
);
};
Loading