-
Notifications
You must be signed in to change notification settings - Fork 16
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
chore: update modal accessibility improvements #1457
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1a942fa
feat: update icon accessibility
Chisomchima 9e7abc3
feat: update modal accessibility improvements
Chisomchima d076fe2
feat: update modal accessibility improvements
Chisomchima 0b34c5b
Merge branch 'LIBS-567/modal-accessibility' of github.com:dhis2/ui in…
Chisomchima 23e02ad
chore: update translation
Chisomchima 77ddb76
Merge branch 'LIBS-567/modal-accessibility' of github.com:dhis2/ui in…
Chisomchima 6855a96
chore: update translation on title
Chisomchima 89edb8b
chore: update translation on title
Chisomchima ec9299d
Merge branches 'LIBS-567/modal-accessibility' and 'LIBS-567/modal-acc…
Chisomchima 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
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 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 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 |
---|---|---|
@@ -1,8 +1,48 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { render, screen, fireEvent } from '@testing-library/react' | ||
import React from 'react' | ||
import { CloseButton } from './close-button.js' | ||
import { Modal } from './modal.js' | ||
|
||
describe('Modal', () => { | ||
describe('Modal Accessibility', () => { | ||
it('closes when ESC key is pressed', () => { | ||
const onCloseMock = jest.fn() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the |
||
render(<Modal onClose={onCloseMock} />) | ||
|
||
const modalElement = screen.getByRole('dialog') | ||
fireEvent.keyDown(modalElement, { key: 'Escape', code: 'Escape' }) | ||
expect(onCloseMock).toHaveBeenCalled() | ||
}) | ||
|
||
it('does not close when "Enter" is pressed', () => { | ||
const onCloseMock = jest.fn() | ||
render(<Modal onClose={onCloseMock} />) | ||
|
||
const modalElement = screen.getByRole('dialog') | ||
fireEvent.keyDown(modalElement, { key: 'Enter', code: 'Enter' }) | ||
expect(onCloseMock).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('does not close when "SpaceBar" is pressed', () => { | ||
const onCloseMock = jest.fn() | ||
render(<Modal onClose={onCloseMock} />) | ||
|
||
const modalElement = screen.getByRole('dialog') | ||
fireEvent.keyDown(modalElement, { key: ' ', code: ' ' }) | ||
expect(onCloseMock).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('has a close button with proper accessibility attributes', async () => { | ||
render(<CloseButton />) | ||
const closeButton = await screen.findByLabelText( | ||
'Close modal dialog' | ||
) | ||
|
||
expect(closeButton).toBeInTheDocument() | ||
expect(closeButton.tagName).toBe('BUTTON') | ||
}) | ||
}) | ||
|
||
describe('Regular dimensions', () => { | ||
it('has the correct dimension styles in its default state', () => { | ||
render(<Modal />) | ||
|
Oops, something went wrong.
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.
I'm not sure if
preventDefault
is necessary, I believe it's just for some HTML-components. Maybe @ismay has some input in regards to this?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.
without the prevent default, keys like enter and space bar work as well, what I want is for escape key only to be able to close the modal.