-
Notifications
You must be signed in to change notification settings - Fork 2.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
[popover2] fix(Popover2): don't react twice to simulated keyboard clicks #6092
Conversation
@adidahiya An alternative fix is to remove the onKeyDown handler that was added to Popover2. Popover (v1) does not support this, and it is ultimately the root cause of the issue. |
Another alternative: Keep the onKeyDown handler, but detect if the target of the event has a |
@justinbhopper thanks for the PR. I like the idea of checking I think we should add unit tests for this change. I poked at the code a bit and tried to add a test but I wasn't able to come up with a failing test (see my work in progress commit here). Can you try adding a unit test or two? I'm not 100% sure but it seems like the behavior is different based on whether |
@adidahiya You were right, This is because autoFocus steals focus as soon as I've added tests based on your WIP example. I had to use a real I've also narrowed the simulated-click check to only be for bp4-button as you requested. |
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 still getting double reactions in the Select2 example in the latest docs preview build (pressing both Enter and Space keys):
@adidahiya Turns out that was caused by #6149. The popover for Select2 was being dismissed because the focus was immediately going into the Filterable input field, and the old logic was interpreting incorrectly as a click on a menu item. While investigating this, I found out that Select2 completely overrides the onKeyDown that is normally handled by Popover2. This means its not possible for the Popover2 to know whether the last keydown event was a keyboard click. Therefore, I coded it to just make the assumption that it should ignore simulated click events from Button if it's current state is already open. If the user presses Enter/Space while the popover is open, the keydown event will already close it, so the simulated click doesn't serve any purpose in any realistic scenario. |
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.
code changes look fine, and I can now open the select popover with enter/space keys. but there is a regression where selecting an item in the list with the Enter key no longer closes the popover in the latest docs preview build:
here is the expected behavior on develop edit: I was actually testing on the last docs release, core v4.18.0 (requires clicking to open):
@adidahiya I just pulled latest from develop and it seems like this regression bug exists there too. I am guessing #6149 had this unintended side effect and its not due to the changes in this PR. The target of the event passed in |
@justinbhopper ah, sorry about that, you're right. There is a regression on develop, I can see it on this commit preview build: 4ee638c#comments. I'll fix that after merging this PR. |
Note for posterity: there was apparently some code in QueryList which attempted to work around this problem already. But it seems like the blueprint/packages/select/src/components/query-list/queryList.tsx Lines 549 to 553 in db161b4
|
Fixes #5775
Checklist
Changes proposed in this pull request:
Adds check in
Popover2
to expect and ignore a simulated click that follows any keyboard click (enter/space) event.Reviewers should focus on:
The root of the bug is caused by the following in single keystroke (up and down) when pressing Enter on a button that is wrapped within a popover:
This PR adds code to track when enter/space happens prior to a click event, and then to ignore any subsequent simulated click event (detected via
isTrusted
flag). If any real click or other keyboard events occur, the tracking property is reset.