-
Notifications
You must be signed in to change notification settings - Fork 122
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): add label for screen readers #1121
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1087852
feat: add label for screen readers
rshen91 4cb8ddc
test: update tests
rshen91 e1c4fcd
Merge remote-tracking branch 'upstream/master' into add-labels
rshen91 e20033a
feat: add aria props
rshen91 2612a2a
Merge remote-tracking branch 'upstream/master' into add-labels
rshen91 a88737d
test: add unit tests
rshen91 19fb650
feat: add code review feedback
rshen91 d9f34a7
Merge remote-tracking branch 'upstream/master' into add-labels
rshen91 532bd0d
fix: update chart api
rshen91 356b754
fix: add code review feedback
rshen91 e770e99
chore: update chart api
rshen91 c1a9b8d
test: updated missed snapshot test
rshen91 6150d2d
fix: add idforchartseries types
rshen91 b81e6f8
feat: remove aria-label
rshen91 d757d9e
refactor(a11y): extract aria attributes in its own selector
markov00 deff638
test: update chart snap
rshen91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
161 changes: 161 additions & 0 deletions
161
src/chart_types/xy_chart/state/chart_state.accessibility.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Store } from 'redux'; | ||
|
||
import { MockGlobalSpec, MockSeriesSpec } from '../../../mocks/specs'; | ||
import { MockStore } from '../../../mocks/store/store'; | ||
import { GlobalChartState } from '../../../state/chart_state'; | ||
import { DEFAULT_A11_SETTINGS } from '../../../state/selectors/get_accessibility_config'; | ||
import { getSettingsSpecSelector } from '../../../state/selectors/get_settings_specs'; | ||
|
||
describe('test accessibility prop defaults', () => { | ||
let store: Store<GlobalChartState>; | ||
beforeEach(() => { | ||
store = MockStore.default(); | ||
MockStore.addSpecs( | ||
[ | ||
MockSeriesSpec.bar({ | ||
data: [ | ||
{ x: 1, y: 10 }, | ||
{ x: 2, y: 5 }, | ||
], | ||
}), | ||
MockGlobalSpec.settings(), | ||
], | ||
store, | ||
); | ||
}); | ||
it('should test defaults', () => { | ||
const state = store.getState(); | ||
const { | ||
ariaDescription, | ||
ariaUseDefaultSummary, | ||
ariaLabelHeadingLevel, | ||
ariaLabel, | ||
ariaLabelledBy, | ||
} = getSettingsSpecSelector(state); | ||
expect(ariaDescription).toBeUndefined(); | ||
expect(ariaUseDefaultSummary).toBeTrue(); | ||
expect(ariaLabelHeadingLevel).toBe(DEFAULT_A11_SETTINGS.labelHeadingLevel); | ||
expect(ariaLabel).toBeUndefined(); | ||
expect(ariaLabelledBy).toBeUndefined(); | ||
}); | ||
}); | ||
describe('custom description for screen readers', () => { | ||
let store: Store<GlobalChartState>; | ||
beforeEach(() => { | ||
store = MockStore.default(); | ||
MockStore.addSpecs( | ||
[ | ||
MockSeriesSpec.bar({ | ||
data: [ | ||
{ x: 1, y: 10 }, | ||
{ x: 2, y: 5 }, | ||
], | ||
}), | ||
MockGlobalSpec.settings(), | ||
], | ||
store, | ||
); | ||
}); | ||
it('should allow user to set a custom description for chart', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
ariaDescription: 'This is sample Kibana data', | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { ariaDescription } = getSettingsSpecSelector(state); | ||
expect(ariaDescription).toBe('This is sample Kibana data'); | ||
}); | ||
it('should be able to disable generated descriptions', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
ariaUseDefaultSummary: false, | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { ariaUseDefaultSummary } = getSettingsSpecSelector(state); | ||
expect(ariaUseDefaultSummary).toBe(false); | ||
}); | ||
}); | ||
describe('custom labels for screen readers', () => { | ||
let store: Store<GlobalChartState>; | ||
beforeEach(() => { | ||
store = MockStore.default(); | ||
MockStore.addSpecs( | ||
[ | ||
MockSeriesSpec.bar({ | ||
data: [ | ||
{ x: 1, y: 10 }, | ||
{ x: 2, y: 5 }, | ||
], | ||
}), | ||
MockGlobalSpec.settings(), | ||
], | ||
store, | ||
); | ||
}); | ||
it('should allow label set by the user', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
ariaLabel: 'Label set by user', | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { ariaLabel } = getSettingsSpecSelector(state); | ||
expect(ariaLabel).toBe('Label set by user'); | ||
}); | ||
it('should allow labelledBy set by the user', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
ariaLabelledBy: 'label-id', | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { ariaLabelledBy } = getSettingsSpecSelector(state); | ||
expect(ariaLabelledBy).toBe('label-id'); | ||
}); | ||
it('should allow users to specify valid heading levels', () => { | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settings({ | ||
ariaLabelHeadingLevel: 'h5', | ||
}), | ||
], | ||
store, | ||
); | ||
const state = store.getState(); | ||
const { ariaLabelHeadingLevel } = getSettingsSpecSelector(state); | ||
expect(ariaLabelHeadingLevel).toBe('h5'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markov00 Setting the summary
id
here would be ideal butaria-labelledby
can't reliably report structured content so we're better off putting it on a simple string. Reporting just the chart type seems appropriate for a supplemental description (better than nothing, type of situation).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
committing in #1118