Skip to content

Commit 8eda19d

Browse files
authored
fix(ui5-shellbar-search): restore focus on button when collapsed (#13523)
1 parent ccf4bcc commit 8eda19d

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,36 @@ describe("Behaviour", () => {
7676
cy.get("[ui5-shellbar-search]")
7777
.should("have.prop", "open", true);
7878
});
79+
80+
it("should collapse and focus the button when Enter is pressed without value", () => {
81+
cy.mount(
82+
<ShellBarSearch/>
83+
);
84+
85+
// Initially expanded
86+
cy.get("[ui5-shellbar-search]")
87+
.should("have.prop", "collapsed", false);
88+
89+
// Focus the input
90+
cy.get("[ui5-shellbar-search]")
91+
.shadow()
92+
.find("input")
93+
.realClick();
94+
95+
// Press Enter without value
96+
cy.get("[ui5-shellbar-search]")
97+
.shadow()
98+
.find("input")
99+
.realPress("Enter");
100+
101+
// Should be collapsed
102+
cy.get("[ui5-shellbar-search]")
103+
.should("have.prop", "collapsed", true);
104+
105+
// Focus should be on the search button
106+
cy.get("[ui5-shellbar-search]")
107+
.shadow()
108+
.find("[ui5-button]")
109+
.should("have.focus");
110+
});
79111
});

packages/fiori/src/ShellBarSearch.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ class ShellBarSearch extends Search {
5353
}
5454
}
5555

56+
_handleEnter() {
57+
if (!this.value && !this.collapsed) {
58+
this.collapsed = true;
59+
60+
setTimeout(() => {
61+
this.focus();
62+
}, 0);
63+
} else {
64+
super._handleEnter();
65+
}
66+
}
67+
5668
_onFocusOutSearch(e: FocusEvent) {
5769
if (isPhone()) {
5870
return;

0 commit comments

Comments
 (0)