Skip to content

Commit bedffcf

Browse files
committed
fix: cover arrow up as well
1 parent 452b233 commit bedffcf

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

packages/fiori/cypress/specs/Search.cy.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("Properties", () => {
8888
.should("be.focused");
8989
});
9090

91-
it("items slot arrow down navigation with groups and headerText", () => {
91+
it("items slot arrow navigation with groups and headerText", () => {
9292
cy.mount(
9393
<Search>
9494
<SearchItemGroup headerText="Group Header 1">
@@ -114,7 +114,7 @@ describe("Properties", () => {
114114

115115
cy.get("ui5-search-item-group")
116116
.shadow()
117-
.find("ui5-li-group-header")
117+
.find("[ui5-li-group-header]")
118118
.should("be.focused");
119119

120120
cy.get("[ui5-search]")
@@ -124,7 +124,7 @@ describe("Properties", () => {
124124
.should("be.focused");
125125
});
126126

127-
it.only("items slot arrow down navigation with groups and no headerText", () => {
127+
it("items slot arrow navigation with groups and no headerText", () => {
128128
cy.mount(
129129
<Search>
130130
<SearchItemGroup>

packages/fiori/src/Search.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class Search extends SearchField {
336336
return StartsWithPerTerm(str, this._flattenItems.filter(item => !this._isGroupItem(item)), "text");
337337
}
338338

339-
_isGroupItem(item: ISearchSuggestionItem) {
339+
_isGroupItem(item: HTMLElement): item is SearchItemGroup {
340340
return item.hasAttribute("ui5-search-item-group");
341341
}
342342

@@ -354,7 +354,8 @@ class Search extends SearchField {
354354
}
355355

356356
_handleArrowDown() {
357-
const firstListItem = this._getItemsList()?.listItems?.[0];
357+
const focusableItems = this._getItemsList().listItems;
358+
const firstListItem = focusableItems.at(0);
358359

359360
if (this.open) {
360361
this._deselectItems();
@@ -449,8 +450,11 @@ class Search extends SearchField {
449450
}
450451

451452
_onItemKeydown(e: KeyboardEvent) {
452-
const isFirstItem = this._flattenItems[0] === e.target;
453-
const isLastItem = this._flattenItems[this._flattenItems.length - 1] === e.target;
453+
const target = e.target as HTMLElement;
454+
const focusedItem = this._isGroupItem(target) ? target?.getFocusDomRef() : target;
455+
const focusableItems = this._getItemsList().listItems;
456+
const isFirstItem = focusableItems.at(0) === focusedItem;
457+
const isLastItem = focusableItems.at(-1) === focusedItem;
454458
const isArrowUp = isUp(e);
455459
const isArrowDown = isDown(e);
456460
const isTab = isTabNext(e);
@@ -602,7 +606,7 @@ class Search extends SearchField {
602606

603607
get _flattenItems(): Array<ISearchSuggestionItem> {
604608
return this.getSlottedNodes<ISearchSuggestionItem>("items").flatMap(item => {
605-
return this._isGroupItem(item) ? [item, ...item.items!] : [item];
609+
return this._isGroupItem(item) ? [item, ...item.items] : [item];
606610
});
607611
}
608612

packages/main/src/ListItemGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class ListItemGroup extends UI5Element {
234234
}
235235

236236
getFocusDomRef() {
237-
return this.groupHeaderItem || this.items[0];
237+
return this.groupHeaderItem || this.items.at(0);
238238
}
239239
}
240240

0 commit comments

Comments
 (0)