-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: click event is fired correctly when focus has changed #20525
Conversation
Thanks for taking the time to open a PR!
|
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.
This is a fascinating and subtle interaction. The event logging style of tests make it really easy to understand exactly what's going on, since you can play with them directly in the AUT iframe.
@@ -332,21 +339,32 @@ export default function (Commands, Cypress, cy, state, config) { | |||
updateTable(id, key, event, value) | |||
} | |||
|
|||
if (event.type === 'keydown') { |
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.
Because you only push events onto this array when type === keydown, there's no need to check the type again later. So this could be simplified to
if (event.type === 'keydown') {
keydownEventTargets.push(event.target);
}
// then below...
// When a space key is pressed on another element, the click event should not be fired.
keydownEventTargets.includes(target)
removing the need to define keydownFiredOnThisElement
at all.
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.
At first, I logged all events. But I realized that it could slow down Cypress a lot. So, the code became this way.
Your code is much simpler.
Thanks!
3af3e45
to
a0f7bd0
Compare
a0f7bd0
to
b13db32
Compare
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
cy.type()
event tests to its own file. #20191User facing changelog
Click events are fired correctly when focus is changed on event handlers.
Additional details
Any implementation details to explain?
Click event emitting is a bit different between enter and space.
Before this PR, Cypress behavior is the opposite (not firing on enter and firing on space). This PR fixes this issue.
How has the user experience changed?
Before: Click event is not sent on enter and sent on space. => Buggy behavior.
After: Click event is sent on enter and not sent on space. => Correct behavior.
PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?