Skip to content
Open
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
27 changes: 27 additions & 0 deletions packages/fiori/cypress/specs/ShellBar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,33 @@ describe("Slots", () => {
cy.get("#search").should("have.prop", "collapsed", true);
});

it("Test pressing Enter on empty search collapses it and keeps ShellBar state in sync", () => {
cy.mount(
<ShellBar id="shellbar" showSearchField={true}>
<ShellBarSearch id="search" slot="searchField"></ShellBarSearch>
</ShellBar>
);

// Initially expanded, ShellBar reflects the expanded state
cy.get("#search").should("have.prop", "collapsed", false);
cy.get("#shellbar").invoke("prop", "showSearchField").should("equal", true);

// Focus the input and press Enter without a value
cy.get("#search")
.shadow()
.find("input")
.realClick();

cy.get("#search")
.shadow()
.find("input")
.realPress("Enter");

// The search collapses AND the ShellBar's own state collapses in sync
cy.get("#search").should("have.prop", "collapsed", true);
cy.get("#shellbar").invoke("prop", "showSearchField").should("equal", false);
});

it("Test showSearchField property is false when using collapsed search field", () => {
cy.mount(
<ShellBar id="shellbar">
Expand Down
3 changes: 3 additions & 0 deletions packages/fiori/src/ShellBarSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class ShellBarSearch extends Search {

_handleEnter() {
if (!this.value && !this.collapsed) {
// Fire `ui5-search` so a host ShellBar collapses in sync; also collapse
// locally for standalone usage (host converges on the same state).
this._handleSearchEvent();
this.collapsed = true;

setTimeout(() => {
Expand Down
Loading