Skip to content

Commit

Permalink
Merge branch 'main' into list-focus-update
Browse files Browse the repository at this point in the history
  • Loading branch information
kgogov authored May 28, 2024
2 parents 131e6dd + f1c0635 commit b4d5f78
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 15 deletions.
4 changes: 4 additions & 0 deletions packages/fiori/src/NotificationList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import NavigationMode from "@ui5/webcomponents-base/dist/types/NavigationMode.js";
import ListItemBase from "@ui5/webcomponents/dist/ListItemBase.js";
import List from "@ui5/webcomponents/dist/List.js";
import NotificationListGroupItem from "./NotificationListGroupItem.js";
Expand All @@ -24,9 +25,12 @@ import {
@customElement("ui5-notification-list")

class NotificationList extends List {
navigationMode = NavigationMode.Auto;

constructor() {
super();
this.accessibleName = NotificationList.i18nFioriBundle.getText(NOTIFICATION_LIST_ACCESSIBLE_NAME);
this._itemNavigation._navigationMode = NavigationMode.Auto;
}

static i18nFioriBundle: I18nBundle;
Expand Down
4 changes: 4 additions & 0 deletions packages/fiori/src/NotificationListGroupItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class NotificationListGroupItem extends NotificationListItemBase {
return;
}

await super._onkeydown(e);

const space = isSpace(e);
const plus = isPlus(e);
const minus = isMinus(e);
Expand All @@ -210,13 +212,15 @@ class NotificationListGroupItem extends NotificationListItemBase {
// expand
if (this.collapsed) {
this.toggleCollapsed();
e.stopImmediatePropagation();
}
}

if (minus || left) {
// collapse
if (!this.collapsed) {
this.toggleCollapsed();
e.stopImmediatePropagation();
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions packages/fiori/src/NotificationListItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
isSpace, isEnter, isDelete, isF10Shift, isEnterShift, isUp, isDown,
isSpace, isDelete, isF10Shift, isEnterShift, isUp, isDown,
} from "@ui5/webcomponents-base/dist/Keys.js";
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
Expand Down Expand Up @@ -484,10 +484,6 @@ class NotificationListItem extends NotificationListItemBase {
async _onkeydown(e: KeyboardEvent) {
await super._onkeydown(e);

if (isEnter(e)) {
this.fireItemPress(e);
}

if (isF10Shift(e)) {
e.preventDefault();
}
Expand All @@ -496,7 +492,12 @@ class NotificationListItem extends NotificationListItemBase {
}

focusSameItemOnNextRow(e: KeyboardEvent) {
const isFocused = document.activeElement === this;
const target = e.target as HTMLElement;
if (!target || target.hasAttribute("ui5-menu-item")) {
return;
}

const isFocused = document.activeElement === this;
if (isFocused || (!isUp(e) && !isDown(e))) {
return;
}
Expand All @@ -516,11 +517,6 @@ class NotificationListItem extends NotificationListItemBase {
return;
}

const target = e.target as HTMLElement;
if (!target) {
return;
}

const sameItemOnNextRow = nextItem.getHeaderDomRef()!.querySelector(`.${target.className}`) as HTMLElement;
if (sameItemOnNextRow && sameItemOnNextRow.offsetParent) {
sameItemOnNextRow.focus();
Expand Down
12 changes: 11 additions & 1 deletion packages/fiori/src/NotificationListItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ 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";

Check failure on line 6 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (base)

Duplicate identifier 'getActiveElement'.

Check failure on line 6 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check

Duplicate identifier 'getActiveElement'.

Check failure on line 6 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (compat)

Duplicate identifier 'getActiveElement'.

Check failure on line 6 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (ai)

Duplicate identifier 'getActiveElement'.

Check failure on line 6 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (main:suite-1)

Duplicate identifier 'getActiveElement'.

Check failure on line 6 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (fiori)

Duplicate identifier 'getActiveElement'.
import ListItemBase from "@ui5/webcomponents/dist/ListItemBase.js";
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
import { getEventMark } from "@ui5/webcomponents-base/dist/MarkedEvents.js";
import { getFirstFocusableElement } from "@ui5/webcomponents-base/dist/util/FocusableElements.js";
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";

Check failure on line 11 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (base)

Duplicate identifier 'getActiveElement'.

Check failure on line 11 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check

Duplicate identifier 'getActiveElement'.

Check failure on line 11 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (compat)

Duplicate identifier 'getActiveElement'.

Check failure on line 11 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (ai)

Duplicate identifier 'getActiveElement'.

Check failure on line 11 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (main:suite-1)

Duplicate identifier 'getActiveElement'.

Check failure on line 11 in packages/fiori/src/NotificationListItemBase.ts

View workflow job for this annotation

GitHub Actions / check (fiori)

Duplicate identifier 'getActiveElement'.

Expand Down Expand Up @@ -65,8 +68,9 @@ class NotificationListItemBase extends ListItemBase {
async _onkeydown(e: KeyboardEvent) {
super._onkeydown(e);

if (isSpace(e)) {
if (isSpace(e) && getEventMark(e) !== "button") {
e.preventDefault();
return;
}

if (isF2(e)) {
Expand All @@ -88,6 +92,12 @@ 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
4 changes: 3 additions & 1 deletion packages/fiori/test/pages/NotificationList_test_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@
</ui5-li-notification-group>
</ui5-notification-list>
</div>

<br >
<br >
<ui5-button>Some button</ui5-button>
<script>
notificationList.addEventListener("ui5-itemClick", function(event) {
clickInput.value = event.detail.item.titleText;
Expand Down
34 changes: 32 additions & 2 deletions packages/fiori/test/specs/NotificationList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ describe("Notification List Item Tests", () => {

assert.strictEqual((await thirdGroupList.getCSSProperty("display")).value, 'none', "The group is collapsed (items are not visible).");
// act
await thirdGroupRoot.click();
await thirdGroup.click(); // expand

assert.strictEqual((await thirdGroupList.getCSSProperty("display")).value, 'block', "The group is expanded (items are visible).");
// act
await thirdGroup.click(); // collapse

assert.strictEqual((await thirdGroupList.getCSSProperty("display")).value, 'none', "The group is collapsed (items are not visible).");
// act
await thirdGroupRoot.keys("ArrowRight");

assert.strictEqual((await thirdGroupList.getCSSProperty("display")).value, 'block', "The group is collapsed (items are not visible).");
assert.strictEqual((await thirdGroupList.getCSSProperty("display")).value, 'block', "The group is expanded (items are visible).");
// act
await thirdGroupRoot.keys("ArrowLeft");

Expand Down Expand Up @@ -351,6 +358,29 @@ describe("Keyboard navigation", () => {

await browser.keys("ArrowUp");
assert.ok(await browser.$("#nlgi1").isFocused(), "First group is focused.");

await browser.keys("ArrowRight");
assert.ok(await browser.$("#nli1").isFocused(), "First item is focused.");

await browser.keys("ArrowRight");
assert.ok(await browser.$("#nli2").isFocused(), "Second item is focused.");

await browser.keys("ArrowRight");
assert.ok(await browser.$("#nlgi2").isFocused(), "Second group is focused.");

await browser.keys("ArrowLeft");
assert.ok(await browser.$("#nlgi2").hasAttribute("collapsed"), "Second group is collapsed.");
assert.ok(await browser.$("#nlgi2").isFocused(), "Second group is focused.");

await browser.keys("ArrowLeft");
assert.ok(await browser.$("#nli2").isFocused(), "Second item is focused.");

await browser.keys("ArrowRight");
assert.ok(await browser.$("#nlgi2").isFocused(), "Second group is focused.");

await browser.keys("ArrowRight");
assert.notOk(await browser.$("#nlgi2").hasAttribute("collapsed"), "Second group is expanded.");
assert.ok(await browser.$("#nlgi2").isFocused(), "Second group is focused.");
});

it("Tab and F2 navigation", async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/main/src/ListItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class ListItemBase extends UI5Element implements ITabbable {
return this._handleTabPrevious(e);
}

if (getEventMark(e) === "button") {
return;
}

if (isSpace(e)) {
e.preventDefault();
}
Expand Down

0 comments on commit b4d5f78

Please sign in to comment.