Skip to content

Commit 2beb1c5

Browse files
authored
fix(ui5-shellbar): fix search field behavior (#1264)
- fix: search field suggestions popup used to open in the left most corner - fix: clicking on suggestions did not take effect due to pop up reposition Root cause: the search field used to close upon interaction with the items in the popover, forcing the popover to reposition itself without knowing the DOM ref of its opener. Solution: the search field is now toggled only by clicking the search icon.
1 parent 32b659d commit 2beb1c5

File tree

5 files changed

+30
-60
lines changed

5 files changed

+30
-60
lines changed

packages/fiori/src/ShellBar.hbs

-4
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@
7070
</div>
7171
</div>
7272

73-
<div class="ui5-shellbar-block-layer">
74-
</div>
75-
7673
<div id="{{_id}}-searchfield-wrapper"
7774
class="ui5-shellbar-search-field"
7875
style="{{styles.searchField}}"
79-
@focusout={{_searchField.focusout}}
8076
>
8177
{{#if searchField.length}}
8278
<slot name="searchField"></slot>

packages/fiori/src/ShellBar.js

+8-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation
55
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
66
import AnimationMode from "@ui5/webcomponents-base/dist/types/AnimationMode.js";
77
import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js";
8-
import { isSpace, isEscape } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
8+
import { isSpace } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
99
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
1010
import StandardListItem from "@ui5/webcomponents/dist/StandardListItem.js";
1111
import List from "@ui5/webcomponents/dist/List.js";
@@ -115,7 +115,7 @@ const metadata = {
115115
/**
116116
* @private
117117
*/
118-
showBlockLayer: {
118+
showSearchField: {
119119
type: Boolean,
120120
},
121121

@@ -440,9 +440,6 @@ class ShellBar extends UI5Element {
440440

441441
this._searchField = {
442442
left: 0,
443-
focusout: event => {
444-
this.showBlockLayer = false;
445-
},
446443
};
447444

448445
this._handleResize = event => {
@@ -636,27 +633,11 @@ class ShellBar extends UI5Element {
636633
}
637634

638635
_onkeydown(event) {
639-
if (isEscape(event)) {
640-
return this._handleEscape(event);
641-
}
642-
643636
if (isSpace(event)) {
644637
event.preventDefault();
645638
}
646639
}
647640

648-
_handleEscape() {
649-
const searchButton = this.shadowRoot.querySelector(".ui5-shellbar-search-button");
650-
651-
if (this.showBlockLayer) {
652-
this.showBlockLayer = false;
653-
654-
setTimeout(() => {
655-
searchButton.focus();
656-
}, 0);
657-
}
658-
}
659-
660641
onEnterDOM() {
661642
ResizeHandler.register(this, this._handleResize);
662643
}
@@ -666,6 +647,12 @@ class ShellBar extends UI5Element {
666647
}
667648

668649
_handleSearchIconPress(event) {
650+
this.showSearchField = !this.showSearchField;
651+
652+
if (!this.showSearchField) {
653+
return;
654+
}
655+
669656
const searchField = this.shadowRoot.querySelector(`#${this._id}-searchfield-wrapper`);
670657
const triggeredByOverflow = event.target.tagName.toLowerCase() === "ui5-li";
671658
const overflowButton = this.shadowRoot.querySelector(".ui5-shellbar-overflow-button");
@@ -683,8 +670,6 @@ class ShellBar extends UI5Element {
683670
"right": right,
684671
});
685672

686-
this.showBlockLayer = true;
687-
688673
setTimeout(() => {
689674
const inputSlot = searchField.children[0];
690675

packages/fiori/src/themes/ShellBar.css

+1-21
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ slot[name="profile"] {
298298
cursor: pointer;
299299
}
300300

301-
:host(:not([show-block-layer])) .ui5-shellbar-search-field {
301+
:host(:not([show-search-field])) .ui5-shellbar-search-field {
302302
display: none;
303303
}
304304

@@ -348,20 +348,6 @@ ui5-icon[data-count]::before {
348348
margin-left: 0.5rem;
349349
}
350350

351-
.ui5-shellbar-block-layer {
352-
top: 0;
353-
left: 0;
354-
right: 0;
355-
bottom: 0;
356-
position: fixed;
357-
outline: 0 none;
358-
z-index: 100;
359-
}
360-
361-
:host(:not([show-block-layer])) .ui5-shellbar-block-layer {
362-
display: none;
363-
}
364-
365351
.ui5-shellbar-search-field {
366352
z-index: 101;
367353
position: absolute;
@@ -386,12 +372,6 @@ ui5-icon[data-count]::before {
386372
outline: 1px dotted var(--sapContent_ContrastFocusColor);
387373
}
388374

389-
:host([show-block-layer]) .ui5-shellbar-search-button {
390-
background: var(--sapHighlightColor);
391-
color: var(--sapShell_Active_TextColor);
392-
border-top-left-radius: 0;
393-
border-bottom-left-radius: 0;
394-
}
395375

396376
.ui5-shellbar-co-pilot-placeholder {
397377
width: 2.75rem;

packages/fiori/test/pages/ShellBar.html

+13
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,20 @@ <h3>ShellBar in Compact</h3>
181181
<ui5-input id="press-input" style="margin-top: 2rem;"></ui5-input>
182182
<ui5-input id="press-input2" style="margin-top: 2rem;"></ui5-input>
183183

184+
185+
<ui5-shellbar>
186+
<ui5-input id="mySearch" slot="searchField" show-suggestions>
187+
<ui5-li>1</ui5-li>
188+
<ui5-li>2</ui5-li>
189+
<ui5-li>3</ui5-li>
190+
</ui5-input>
191+
</ui5-shellbar>
192+
184193
<script>
194+
mySearch.addEventListener("suggestionItemSelect", function (event) {
195+
 console.log(event);
196+
});
197+
185198
shellbar.addEventListener("ui5-profileClick", function(event) {
186199
popover.openBy(event.detail.targetRef);
187200
window["press-input"].value = "Profile";

packages/fiori/test/specs/ShellBar.spec.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,17 @@ describe("Component Behavior", () => {
272272
assert.strictEqual(input.getValue(), "Application 2", "Input value is set by click event of the second menu item");
273273
});
274274

275-
it("tests if searchfield appears when clicking on search icon", () => {
275+
it("tests if searchfield toggles when clicking on search icon", () => {
276276
const searchIcon = browser.$("#shellbar").shadow$(".ui5-shellbar-search-button");
277277
const searchField = browser.$("#shellbar ui5-input");
278-
const blockLayer = browser.$("#shellbar").shadow$(".ui5-shellbar-block-layer");
279278

280279
assert.strictEqual(searchField.isDisplayed(), false, "Search is hidden by default");
281280

282281
searchIcon.click();
283282
assert.strictEqual(searchField.isDisplayed(), true, "Search is visible after clicking on icon");
284283

285-
// focus out the input
286-
blockLayer.click();
287-
assert.strictEqual(searchField.isDisplayed(), false, "Search is hidden when focussed out");
284+
searchIcon.click();
285+
assert.strictEqual(searchField.isDisplayed(), false, "Search is hidden after clicking again on the icon");
288286
});
289287
});
290288

@@ -345,25 +343,23 @@ describe("Component Behavior", () => {
345343
assert.strictEqual(input.getValue(), "Product Switch", "Input value is set by click event of Product Switch icon");
346344
});
347345

348-
it("tests if searchfield appears when clicking on search icon", () => {
346+
it("tests if searchfield toggles when clicking on search icon", () => {
349347
const overflowButton = browser.$("#shellbar").shadow$(".ui5-shellbar-overflow-button");
350348
const searchField = browser.$("#shellbar ui5-input");
351349
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#shellbar")
352350
const overflowPopover = browser.$(`.${staticAreaItemClassName}`).shadow$(".ui5-shellbar-overflow-popover");
353351
const searchListItem = overflowPopover.$("ui5-list ui5-li:nth-child(1)");
354-
const blockLayer = browser.$("#shellbar").shadow$(".ui5-shellbar-block-layer");
355-
356352

357353
assert.strictEqual(searchField.isDisplayed(), false, "Search is hidden by default");
358354

359355
overflowButton.click();
360356
searchListItem.click();
361357

362-
assert.strictEqual(searchField.isDisplayed(), true, "Search is visible after clicking on icon");
358+
assert.strictEqual(searchField.isDisplayed(), true, "Search is visible after clicking on the search icon within the overflow");
363359

364-
// focus out the input
365-
blockLayer.click();
366-
assert.strictEqual(searchField.isDisplayed(), false, "Search is hidden when focussed out");
360+
overflowButton.click();
361+
searchListItem.click();
362+
assert.strictEqual(searchField.isDisplayed(), false, "Search is hidden after clicking on the search icon agian");
367363
});
368364
});
369365
});

0 commit comments

Comments
 (0)