-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Modal: use code instead of keyCode for keyboard events #43429
Conversation
Size Change: -2 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
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 |
@@ -140,6 +154,7 @@ describe( 'Confirm', () => { | |||
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"
|
||
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
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
Modal
component to rely oncode
instead ofkeyCode
for keyboard eventsWhy?
keyCode
is deprecated, and replaced bycode
How?
Easy swap of values
Testing Instructions
On Storybook, make sure that the
Modal
still closes when pressing theEscape
key (if theshouldCloseOnEsc
property is set totrue
)