Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/main/src/SegmentedButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsSco
import {
isSpace,
isEnter,
isShift,
isEscape,
} from "@ui5/webcomponents-base/dist/Keys.js";
import { SEGMENTEDBUTTON_ARIA_DESCRIPTION, SEGMENTEDBUTTON_ARIA_DESCRIBEDBY } from "./generated/i18n/i18n-defaults.js";
import "./SegmentedButtonItem.js";
Expand Down Expand Up @@ -113,13 +115,16 @@ class SegmentedButton extends UI5Element {

_selectedItem?: ISegmentedButtonItem;

_actionCanceled: boolean;

constructor() {
super();

this._itemNavigation = new ItemNavigation(this, {
getItemsCallback: () => this.navigatableItems,
});
this.hasPreviouslyFocusedItem = false;
this._actionCanceled = false;
}

onBeforeRendering() {
Expand Down Expand Up @@ -200,15 +205,22 @@ class SegmentedButton extends UI5Element {

_onkeydown(e: KeyboardEvent) {
if (isEnter(e)) {
this._selectItem(e);
this._selectItem(e); // Enter key behavior remains unaffected
} else if (isSpace(e)) {
e.preventDefault();
e.preventDefault(); // Prevent scrolling
this._actionCanceled = false; // Reset the action cancellation flag
} else if (isShift(e) || isEscape(e)) {
this._actionCanceled = true; // Set the flag to cancel the action
}
}

_onkeyup(e: KeyboardEvent) {
if (isSpace(e)) {
this._selectItem(e);
// Only select if the action was not canceled
if (!this._actionCanceled) {
this._selectItem(e);
}
this._actionCanceled = false; // Reset the flag after handling
}
}

Expand Down
Loading