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

feat(a11y): allow user to pass custom description for screen readers #1111

Merged
merged 12 commits into from
Apr 14, 2021

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Apr 8, 2021

Summary

Fixes #1097
This PR allows the user of elastic charts to pass in a description via the <Settings /> component (only for xy_charts) to be read by a screen reader.

In the case where users descriptions are informational enough, they are able to disable the default generated series types through useDefaultSummary, which by default is true.

Checklist

Delete any items that are not applicable to this PR.

  • Unit tests were updated or added to match the most common scenarios
  • Updated storybook to show functionality (a11y_custom_description within test_cases to test out with VoiceOver on Safari.)

@rshen91 rshen91 added :accessibility Accessibility related issue :xy Bar/Line/Area chart related labels Apr 12, 2021
@codecov-io
Copy link

codecov-io commented Apr 12, 2021

Codecov Report

Merging #1111 (75df86b) into master (6e1f223) will increase coverage by 0.46%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1111      +/-   ##
==========================================
+ Coverage   72.22%   72.68%   +0.46%     
==========================================
  Files         387      404      +17     
  Lines       12007    12353     +346     
  Branches     2623     2677      +54     
==========================================
+ Hits         8672     8979     +307     
- Misses       3310     3341      +31     
- Partials       25       33       +8     
Flag Coverage Δ
unittests 72.25% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/specs/constants.ts 100.00% <ø> (ø)
src/specs/settings.tsx 90.32% <ø> (ø)
.../chart_types/xy_chart/renderer/canvas/xy_chart.tsx 95.50% <100.00%> (+0.70%) ⬆️
src/mocks/scale/index.ts 100.00% <0.00%> (ø)
src/mocks/utils.ts 100.00% <0.00%> (ø)
src/mocks/series/utils.ts 100.00% <0.00%> (ø)
src/mocks/specs/index.ts 100.00% <0.00%> (ø)
src/mocks/geometries.ts 92.85% <0.00%> (ø)
src/mocks/theme.ts 86.66% <0.00%> (ø)
src/mocks/specs/specs.ts 83.33% <0.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b712ab...75df86b. Read the comment docs.

@rshen91 rshen91 marked this pull request as ready for review April 12, 2021 21:47
debug: boolean;
// @alpha
debugState?: boolean;
disableGeneratedSeriesTypes: boolean;

Choose a reason for hiding this comment

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

Just reading this prop name, I'm not sure what it means... What do you think about something like disableGeneratedDescription?

Copy link
Member

Choose a reason for hiding this comment

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

I also really like the way you named both properties in the issue example:
description and useDefaultSummary
they are generic and simple.
the word custom doesn't add much to that property meaning

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you both please see 3b13cc9

Choose a reason for hiding this comment

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

Looks like you missed this file for renaming these variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😭 right, thanks! 76cc6b3

@@ -78,6 +80,8 @@ export interface ReactiveChartStateProps {
annotationSpecs: AnnotationSpec[];
panelGeoms: PanelGeoms;
seriesTypes: Set<SeriesType>;
customDescription: string | undefined;

Choose a reason for hiding this comment

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

I think it's effectively equivalent but I think defining this as an optional prop communicates the intent a little better.

Suggested change
customDescription: string | undefined;
customDescription?: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Smart! Thank you 3b13cc9

@@ -178,11 +184,19 @@ class XYChartComponent extends React.Component<XYChartProps> {
}}
// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role
role="presentation"
aria-describedby="get_custom_description"

Choose a reason for hiding this comment

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

You'll want to replace this with a randomly generated id – if a user renders two charts, each with a unique description, you'll end up getting only the first id read off for both charts.

You'll also want to conditionally add the attribute. An empty description will sometimes still get read out (something like "description empty") but probably just want to ignore it.

Suggested change
aria-describedby="get_custom_description"
{...(customDescription ? {'aria-describedby': randomId} : {})}

Copy link
Member

Choose a reason for hiding this comment

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

you can use the chartId, that is random and unique per chart, + some postfix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I am open to feedback about 3b13cc9 thank you!

@@ -78,6 +80,8 @@ export interface ReactiveChartStateProps {
annotationSpecs: AnnotationSpec[];
panelGeoms: PanelGeoms;
seriesTypes: Set<SeriesType>;
customDescription: string | undefined;

Choose a reason for hiding this comment

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

We should also accept something along the lines of a descriptionId. If the description is already rendered somewhere else on the page, we want users to be able to just point to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok let me know if I'm following - 3b13cc9 thank you!

@@ -178,11 +184,19 @@ class XYChartComponent extends React.Component<XYChartProps> {
}}
// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role
role="presentation"
aria-describedby="get_custom_description"
Copy link
Member

Choose a reason for hiding this comment

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

you can use the chartId, that is random and unique per chart, + some postfix

src/chart_types/xy_chart/renderer/canvas/xy_chart.tsx Outdated Show resolved Hide resolved
debug: boolean;
// @alpha
debugState?: boolean;
disableGeneratedSeriesTypes: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I also really like the way you named both properties in the issue example:
description and useDefaultSummary
they are generic and simple.
the word custom doesn't add much to that property meaning

src/chart_types/xy_chart/state/chart_state.a11y.test.ts Outdated Show resolved Hide resolved
@rshen91 rshen91 requested review from markov00 and myasonik April 13, 2021 17:17
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM all the changes are fine, just one last minor detail in the playground (you can also checkout the playground code from master so we don't introduce changes there at all)


export class Playground extends React.Component {
render() {
return (
<div className="App">
<Chart size={[500, 200]}>
<Settings customDescription="This is an area chart showing kibana sample data." />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<Settings customDescription="This is an area chart showing kibana sample data." />
<Settings description="This is an area chart showing kibana sample data." />

@rshen91 rshen91 merged commit 2ee1b91 into elastic:master Apr 14, 2021
@rshen91 rshen91 deleted the pass-labels branch April 14, 2021 14:17
nickofthyme pushed a commit that referenced this pull request Apr 15, 2021
# [28.2.0](v28.1.0...v28.2.0) (2021-04-15)

### Bug Fixes

* **xy:** consider `useDefaultGroupDomain` on scale config ([#1119](#1119)) ([c1b59f2](c1b59f2)), closes [#1087](#1087)

### Features

* **a11y:** allow user to pass custom description for screen readers ([#1111](#1111)) ([2ee1b91](2ee1b91)), closes [#1097](#1097)
* **partition:** add debuggable state ([#1117](#1117)) ([d7fc206](d7fc206)), closes [#917](#917)
@nickofthyme
Copy link
Collaborator

🎉 This PR is included in version 28.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label Apr 15, 2021
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [28.2.0](elastic/elastic-charts@v28.1.0...v28.2.0) (2021-04-15)

### Bug Fixes

* **xy:** consider `useDefaultGroupDomain` on scale config ([opensearch-project#1119](elastic/elastic-charts#1119)) ([269ff1a](elastic/elastic-charts@269ff1a)), closes [opensearch-project#1087](elastic/elastic-charts#1087)

### Features

* **a11y:** allow user to pass custom description for screen readers ([opensearch-project#1111](elastic/elastic-charts#1111)) ([a0020ba](elastic/elastic-charts@a0020ba)), closes [#1097](elastic/elastic-charts#1097)
* **partition:** add debuggable state ([opensearch-project#1117](elastic/elastic-charts#1117)) ([08f8baf](elastic/elastic-charts@08f8baf)), closes [opensearch-project#917](elastic/elastic-charts#917)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:accessibility Accessibility related issue released Issue released publicly :xy Bar/Line/Area chart related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing description props to <canvas> element
5 participants