Skip to content

Commit a5cf4f0

Browse files
authored
feat(ui5-shellbar): keyboard support added for home/end (#11886)
Fixes: #11789
1 parent 40399a9 commit a5cf4f0

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ describe("Slots", () => {
504504
cy.mount(
505505
<ShellBar id="shellbar" primaryTitle="Product Title" showNotifications={true}></ShellBar>
506506
);
507-
507+
508508
cy.get("#shellbar").as("shellbar");
509-
509+
510510
// Add search field after a timeout (simulating real-world scenario)
511511
cy.get("@shellbar").then(shellbar => {
512512
setTimeout(() => {
@@ -516,15 +516,15 @@ describe("Slots", () => {
516516
shellbar.get(0).appendChild(searchField);
517517
}, 100);
518518
});
519-
519+
520520
// Wait for the search field to be added
521521
cy.get("#delayed-search", { timeout: 1000 }).should("exist");
522-
522+
523523
// Search should now be visible and collapsed
524524
cy.get("#shellbar [slot='searchField']")
525525
.should("exist")
526526
.should("have.prop", "collapsed", true);
527-
527+
528528
// click the searchField to expand it
529529
cy.get("#shellbar [slot='searchField']")
530530
.click()
@@ -788,6 +788,30 @@ describe("Keyboard Navigation", () => {
788788
cy.get("@nativeInput").type("{rightArrow}");
789789
cy.get("@nativeInput").should("be.focused");
790790
});
791+
792+
it("Should focus the last ShellBar item on End key press", () => {
793+
cy.mount(
794+
<ShellBar id="shellbar" showSearchField={true}>
795+
<Button slot="content">Test Button 1</Button>
796+
<Button id="button" slot="content">Test Button 2</Button>
797+
<ShellBarSearch id="sbSearch" slot="searchField" value="test value"></ShellBarSearch>
798+
</ShellBar>
799+
);
800+
cy.get("#button").shadow().find("button").focus().type('{end}');
801+
cy.get("#sbSearch").should("be.focused");
802+
});
803+
804+
it("Should focus the first ShellBar item on Home key press", () => {
805+
cy.mount(
806+
<ShellBar id="shellbar" showSearchField={true}>
807+
<Button id="button1" slot="content">Test Button 1</Button>
808+
<Button id="button2" slot="content">Test Button 2</Button>
809+
<ShellBarSearch slot="searchField" value="test value"></ShellBarSearch>
810+
</ShellBar>
811+
);
812+
cy.get("#button2").shadow().find("button").focus().type('{home}');
813+
cy.get("#button1").shadow().find("button").should("be.focused");
814+
});
791815
});
792816

793817
describe("Branding slot", () => {
@@ -796,7 +820,8 @@ describe("Branding slot", () => {
796820
<ShellBar id="shellbar" primaryTitle="Primary Title">
797821
<img id="mainLogo" slot="logo" src="https://upload.wikimedia.org/wikipedia/commons/5/59/SAP_2011_logo.svg" />
798822

799-
<ShellBarBranding brandingTitle="Branding Comp" href="https://www.w3schools.com" target="_blank" slot="branding">
823+
<ShellBarBranding href="https://www.w3schools.com" target="_blank" slot="branding">
824+
Branding Comp
800825
<img id="brandingLogo" src="https://upload.wikimedia.org/wikipedia/commons/5/59/SAP_2011_logo.svg" slot="logo"/>
801826
</ShellBarBranding>
802827
</ShellBar>

packages/fiori/src/ShellBar.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
isEnter,
1313
isLeft,
1414
isRight,
15+
isHome,
16+
isEnd,
1517
} from "@ui5/webcomponents-base/dist/Keys.js";
1618
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js";
1719
import { getTabbableElements } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
@@ -675,7 +677,7 @@ class ShellBar extends UI5Element {
675677
}
676678

677679
_onKeyDown(e: KeyboardEvent) {
678-
if (!isLeft(e) && !isRight(e)) {
680+
if (!isLeft(e) && !isRight(e) && !isHome(e) && !isEnd(e)) {
679681
return;
680682
}
681683

@@ -707,6 +709,12 @@ class ShellBar extends UI5Element {
707709
this._focusPreviousItem(items, currentIndex);
708710
} else if (isRight(e)) {
709711
this._focusNextItem(items, currentIndex);
712+
} else if (isHome(e)) {
713+
// Move focus to the first ShellBar item
714+
items[0]?.focus();
715+
} else if (isEnd(e)) {
716+
// Move focus to the last ShellBar item
717+
items[items.length - 1]?.focus();
710718
}
711719
}
712720
}

0 commit comments

Comments
 (0)