This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(Dialog): add default aria-labelledby if not provided #1298
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
52739a3
generated default aria-labelledby
silviuaavram 7e7af6b
moved to behavior and added desdcribedby
silviuaavram 8b1fd52
updated changelog
silviuaavram adc7244
updated description of method
silviuaavram d9f9cff
added specifications and a definition
silviuaavram 4dfb4d6
Merge branch 'master' into feat/dialog-default-aria-labelledby
silviuaavram cfc18c1
renamed the specs and definition
silviuaavram faa001c
Merge branch 'feat/dialog-default-aria-labelledby' of https://github.…
silviuaavram e583074
Merge branch 'master' into feat/dialog-default-aria-labelledby
silviuaavram 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 hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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
117 changes: 117 additions & 0 deletions
117
packages/react/test/specs/components/Dialog/Dialog-test.tsx
This file contains hidden or 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,117 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import Dialog from 'src/components/Dialog/Dialog' | ||
| import Button from 'src/components/Button/Button' | ||
| import { getRenderedAttribute } from 'test/specs/commonTests' | ||
| import { mountWithProvider } from 'test/utils' | ||
|
|
||
| describe('Dialog', () => { | ||
| describe('accessibility', () => { | ||
| it('applies aria-label if provided as prop', () => { | ||
| const ariaLabel = 'super label' | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} aria-label={ariaLabel} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-label', '')).toBe(ariaLabel) | ||
| }) | ||
|
|
||
| it('applies aria-labelledby if provided as prop', () => { | ||
| const ariaLabelledBy = 'element-id' | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} aria-labelledby={ariaLabelledBy} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-labelledby', '')).toBe(ariaLabelledBy) | ||
| }) | ||
|
|
||
| it('applies default aria-labelledby as header id if header with id exists', () => { | ||
| const headerId = 'element-id' | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} header={{ id: headerId }} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-labelledby', '')).toBe(headerId) | ||
| }) | ||
|
|
||
| it('applies default aria-labelledby as generated header id if header without id exists', () => { | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} header={'Welcome to my life'} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialogHeaderId = wrapper | ||
| .find(`.${Dialog.slotClassNames.header}`) | ||
| .filterWhere(n => typeof n.type() === 'string') | ||
| .getDOMNode().id | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(dialogHeaderId).toMatch(/dialog-header-\d+/) | ||
| expect(getRenderedAttribute(dialog, 'aria-labelledby', '')).toBe(dialogHeaderId) | ||
| }) | ||
|
|
||
| it('does not apply default aria-labelledby as header id if aria-label is supplied as prop', () => { | ||
| const wrapper = mountWithProvider( | ||
| <Dialog | ||
| trigger={<Button content="Open a dialog" />} | ||
| aria-label={'bla-bla-label'} | ||
| header={{ id: 'bla-bla-id' }} | ||
| />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-labelledby', '')).toBe(undefined) | ||
| }) | ||
|
|
||
| it('does not apply default aria-labelledby as header id if header is not supplied as prop', () => { | ||
| const wrapper = mountWithProvider(<Dialog trigger={<Button content="Open a dialog" />} />) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-labelledby', '')).toBe(undefined) | ||
| }) | ||
|
|
||
| it('applies aria-describedby if provided as prop', () => { | ||
| const ariaDescribedBy = 'element-id' | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} aria-describedby={ariaDescribedBy} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-describedby', '')).toBe(ariaDescribedBy) | ||
| }) | ||
|
|
||
| it('applies default aria-describedby as content id if content with id exists', () => { | ||
| const contentId = 'element-id' | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} content={{ id: contentId }} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(getRenderedAttribute(dialog, 'aria-describedby', '')).toBe(contentId) | ||
| }) | ||
|
|
||
| it('applies default aria-describedby as generated content id if content without id exists', () => { | ||
| const wrapper = mountWithProvider( | ||
| <Dialog trigger={<Button content="Open a dialog" />} content={'It is so awesome.'} />, | ||
| ) | ||
| wrapper.find('.ui-button').simulate('click') | ||
| const dialogContentId = wrapper | ||
| .find(`.${Dialog.slotClassNames.content}`) | ||
| .filterWhere(n => typeof n.type() === 'string') | ||
| .getDOMNode().id | ||
| const dialog = wrapper.find(`.${Dialog.className}`) | ||
|
|
||
| expect(dialogContentId).toMatch(/dialog-content-\d+/) | ||
| expect(getRenderedAttribute(dialog, 'aria-describedby', '')).toBe(dialogContentId) | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.