-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Modal: use code instead of keyCode for keyboard events #43429
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
Conversation
|
Size Change: -2 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
mirka
left a comment
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.
Good move 👍
I realized that |
| const confirmDialog = screen.getByRole( 'dialog' ); | ||
|
|
||
| //The overlay click is handled by detecting an onBlur from the modal frame. | ||
| // TODO: replace with `@testing-library/user-event` |
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 tried to simulate a click on document.body and even on the Modal's overlay, but that was not enough. I therefore decided to leave fireEvent for now to unblock the rest of this PR (same for another test a few lines below)
| const frame = wrapper.baseElement.querySelector( | ||
| '.components-modal__frame' | ||
| ); | ||
| const confirmDialog = screen.getByRole( 'dialog' ); |
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.
.components-modal__frame is the element with role="dialog"
| // TODO: replace with `@testing-library/user-event` | ||
| fireEvent.blur( confirmDialog ); | ||
|
|
||
| jest.useRealTimers(); |
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.
There wasn't any need for fake timers to start with
| 'aria-labelledby', | ||
| 'title-id' | ||
| expect( screen.getByRole( 'dialog' ) ).toHaveAccessibleName( | ||
| 'Modal Title Text' |
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.
The previous test was not actually testing for the computed accessible name
| const titleId = within( dialog ).getByText( 'Test Title' ).id; | ||
| expect( dialog ).toHaveAttribute( 'aria-labelledby', titleId ); | ||
| expect( screen.getByRole( 'dialog' ) ).toHaveAccessibleName( | ||
| 'Modal Title Attribute' |
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.
Same here — the previous test was not actually testing for the computed accessible name
tyxla
left a comment
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.
Beautiful, thanks for fixing this one so quickly 🚀 Also love all the side improvements
What?
Refactor the
Modalcomponent to rely oncodeinstead ofkeyCodefor keyboard eventsWhy?
keyCodeis deprecated, and replaced bycodeHow?
Easy swap of values
Testing Instructions
On Storybook, make sure that the
Modalstill closes when pressing theEscapekey (if theshouldCloseOnEscproperty is set totrue)