Skip to content

Commit

Permalink
fix: allow tab "forms" navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
dobrinyonkov committed Sep 30, 2024
1 parent 71b8e53 commit a93b895
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 663 deletions.
20 changes: 12 additions & 8 deletions packages/main/src/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import debounce from "@ui5/webcomponents-base/dist/util/debounce.js";
import isElementInView from "@ui5/webcomponents-base/dist/util/isElementInView.js";
import Orientation from "@ui5/webcomponents-base/dist/types/Orientation.js";
import MovePlacement from "@ui5/webcomponents-base/dist/types/MovePlacement.js";
import { getTabbableElements } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";
import ListSelectionMode from "./types/ListSelectionMode.js";
import ListGrowingMode from "./types/ListGrowingMode.js";
import type ListAccessibleRole from "./types/ListAccessibleRole.js";
Expand Down Expand Up @@ -1186,26 +1188,28 @@ class List extends UI5Element {
}

onForwardBefore(e: CustomEvent) {
const activeElement = getActiveElement() as HTMLElement;
const item = e.detail.item as ListItemBase;
const target = getNormalizedTarget(e.target as HTMLElement);
const isFirstItem = this.getItems().indexOf(item) === 0;
const isFirstTabbable = getTabbableElements(item).shift() === getActiveElement();
const isItemFocused = item.getFocusDomRef() === activeElement;

this.setPreviouslyFocusedItem(e.target as ListItemBase);

if (target !== item.getFocusDomRef()) {
return;
if (isItemFocused && (isFirstItem && !isFirstTabbable)) {
this.focusBeforeElement();
e.stopPropagation();
}

this.focusBeforeElement();
e.stopPropagation();
}

onForwardAfter(e: CustomEvent) {
const item = e.detail.item as ListItemBase;
const target = getNormalizedTarget(e.target as HTMLElement);
const isLastItem = this.getItems().indexOf(item) === this.getItems().length - 1;
const isLastTabbable = isLastItem && getTabbableElements(item).pop() === getActiveElement();

this.setPreviouslyFocusedItem(item);

if (target !== item.getFocusDomRef()) {
if (!isLastTabbable) {
return;
}

Expand Down
Loading

0 comments on commit a93b895

Please sign in to comment.