Skip to content
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(ui5-list): enable forms mode navigation #9904

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions packages/fiori/src/NotificationListItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { isSpace, isF2 } from "@ui5/webcomponents-base/dist/Keys.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { getTabbableElements } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";
import ListItemBase from "@ui5/webcomponents/dist/ListItemBase.js";
import { getEventMark } from "@ui5/webcomponents-base/dist/MarkedEvents.js";
Expand Down Expand Up @@ -99,12 +98,6 @@ class NotificationListItemBase extends ListItemBase {
return this.getFocusDomRef();
}

shouldForwardTabAfter() {
const aContent = getTabbableElements(this.getHeaderDomRef()!);

return aContent.length === 0 || (aContent[aContent.length - 1] === getActiveElement());
}

static async onDefine() {
NotificationListItemBase.i18nFioriBundle = await getI18nBundle("@ui5/webcomponents-fiori");
}
Expand Down
57 changes: 22 additions & 35 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 @@ -546,8 +548,6 @@ class List extends UI5Element {

this._handleResize = this.checkListInViewport.bind(this);

this._handleResize = this.checkListInViewport.bind(this);

// Indicates the List bottom most part has been detected by the IntersectionObserver
// for the first time.
this.initialIntersection = true;
Expand Down Expand Up @@ -893,11 +893,6 @@ class List extends UI5Element {
_onkeydown(e: KeyboardEvent) {
if (isCtrl(e)) {
this._moveItem(e.target as ListItemBase, e);
return;
}

if (isTabNext(e)) {
this._handleTabNext(e);
}
}

Expand Down Expand Up @@ -995,31 +990,6 @@ class List extends UI5Element {
this.fireEvent("load-more");
}

/*
* KEYBOARD SUPPORT
*/
_handleTabNext(e: KeyboardEvent) {
let lastTabbableEl;
const target = getNormalizedTarget(e.target as HTMLElement);

if (!lastTabbableEl) {
return;
}

if (lastTabbableEl === target) {
if (this.getFirstItem(x => x.selected && x._focusable)) {
this.focusFirstSelectedItem();
} else if (this.getPreviouslyFocusedItem()) {
this.focusPreviouslyFocusedItem();
} else {
this.focusFirstItem();
}

e.stopImmediatePropagation();
e.preventDefault();
}
}

_onfocusin(e: FocusEvent) {
const target = getNormalizedTarget(e.target as HTMLElement);
// If the focusin event does not origin from one of the 'triggers' - ignore it.
Expand Down Expand Up @@ -1218,13 +1188,30 @@ class List extends UI5Element {
}

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

this.setPreviouslyFocusedItem(e.target as ListItemBase);
this.focusBeforeElement();
e.stopPropagation();

if (isItemFocused && (isFirstItem && !isFirstTabbable)) {
this.focusBeforeElement();
e.stopPropagation();
}
}

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

this.setPreviouslyFocusedItem(item);

if (!isLastTabbable) {
return;
}

if (!this.growsWithButton) {
this.focusAfterElement();
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/ListItem.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import { getEventMark } from "@ui5/webcomponents-base/dist/MarkedEvents.js";
import {
isSpace, isEnter, isDelete, isF2,
isSpace, isEnter, isDelete, isF2, isF7,
} from "@ui5/webcomponents-base/dist/Keys.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
Expand Down Expand Up @@ -262,7 +262,7 @@ abstract class ListItem extends ListItemBase {
this.activate();
}

if (isF2(e)) {
if (isF2(e) || isF7(e)) {
const activeElement = getActiveElement();
const focusDomRef = this.getFocusDomRef()!;

Expand Down
32 changes: 4 additions & 28 deletions packages/main/src/ListItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import event from "@ui5/webcomponents-base/dist/decorators/event.js";
import type { ITabbable } from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
import type { ClassMap } from "@ui5/webcomponents-base/dist/types.js";
import { getTabbableElements } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
import {
isEnter,
isSpace,
isTabNext,
isTabPrevious,
} from "@ui5/webcomponents-base/dist/Keys.js";
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";
import { getEventMark } from "@ui5/webcomponents-base/dist/MarkedEvents.js";

// Styles
Expand Down Expand Up @@ -165,29 +163,13 @@ class ListItemBase extends UI5Element implements ITabbable {
}

_handleTabNext(e: KeyboardEvent) {
if (this.shouldForwardTabAfter()) {
if (!this.fireEvent("_forward-after", {}, true)) {
e.preventDefault();
}
if (!this.fireEvent("_forward-after", { item: this, target: e.target }, true)) {
e.preventDefault();
}
}

_handleTabPrevious(e: KeyboardEvent) {
const target = e.target as HTMLElement;

if (this.shouldForwardTabBefore(target)) {
this.fireEvent("_forward-before");
}
}

/**
* Determines if th current list item either has no tabbable content or
* [Tab] is performed onto the last tabbale content item.
*/
shouldForwardTabAfter() {
const aContent = getTabbableElements(this.getFocusDomRef()!);

return aContent.length === 0 || (aContent[aContent.length - 1] === getActiveElement());
this.fireEvent("_forward-before", { item: this, target: e.target });
}

/**
Expand Down Expand Up @@ -223,13 +205,7 @@ class ListItemBase extends UI5Element implements ITabbable {
}

get _effectiveTabIndex() {
if (!this._focusable) {
return -1;
}
if (this.selected) {
return 0;
}
return this.forcedTabIndex;
return -1;
}
}

Expand Down
Loading
Loading