-
Notifications
You must be signed in to change notification settings - Fork 273
fix(ui5-split-button): fire click event when focused with shift + tab #11197
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR fixes an issue where the ui5-split-button failed to fire the click event when focused with Shift + Tab and refines the key event handling logic.
- Removed the onFocusIn handler from the button template.
- Renamed and replaced the flag handling (using _shiftOrEscapePressedDuringSpace instead of _shiftOrEscapePressed) to address conflicts with combined key presses.
- Refactored key event handlers to reset UI states and correctly manage default actions.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
packages/main/src/SplitButtonTemplate.tsx | Removed the onFocusIn attribute from the button template to prevent premature state resetting. |
packages/main/src/SplitButton.ts | Renamed the flag and refactored key event handling logic for correct click event firing behavior. |
} | ||
|
||
if (this._isShiftOrEscape(e)) { | ||
this._handleShiftOrEscapePressed(); | ||
if (isEnter(e)) { |
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 suggest combining this statement and the one below into a variable like "shouldToggleOffActiveButton" and then if (should ...): this._buttonActive = false
to avoid the duplicate code
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 don't really like the idea of always having flags to follow the states. Can we use checks for modifier keys? Can we try this? If not we can fallback to this solution, but let's explore using checks in the events for key modifiers. An example can be seein in Keys.js in the method isSpaceShift
.
Main Problem
There was an issue, where if the
ui5-split-button
was to be focused by usingShift + Tab
combination, theclick
event wasn't firing, after the first time a default action was executed (pressedEnter
orSpace
).The reason behind this, was a flag called
_shiftOrEscapePressed
.Since the component has a handler for
focus-in
event which was just early returning if the componentmatches
the:focus-within
CSS selector, which was causing the flag to NOT reset. Therefore the component wasn't firingclick
event, due to the condition:Solutions
_shiftOrEscapePressedDuringSpace
, which handles the cases only whenShift
orEscape
keys are pressed simultaneously with theSpace
Bar.ArrowUp/Down
keys andTab/Shift + Tab
.Shift/Escape
keys now correctly prevent events from firing;arrow-button
firedclick
ANDarrow-click
events.Note: Test will be written in a separate change when migrating the
SplitButton.spec.js
file to aSplitButton.cy.tsx
Fixes: #11115