Skip to content

Commit c65010b

Browse files
authored
fix(ui5-shellbar): fix search field focus handling (#1636)
**Issue**: the valueStateMsg popover does not show up when the user clicks on the search icon. **Root cause**: the ShellBar uses a timeout to focus the input to ensure it is displayed and ready to be focused, but sometimes the timeout executes too late. - First, the Iinput checks (onAfterRendering) if it should show a valueStateMessage and one of the requirements is to be on focus, which is still false (the timeout is called later) and does not show the popover. - Then, the timeout is called, moves the focus to the input, but it does not trigger re-rendering and the popover does not show up. **Solution:** update the state (Input "focused" property) immediately, keep the focus move delayed. Fixes: #1590
1 parent 396993e commit c65010b

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

packages/fiori/src/ShellBar.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,19 @@ class ShellBar extends UI5Element {
658658
"right": right,
659659
});
660660

661-
setTimeout(() => {
662-
const inputSlot = searchField.children[0];
663661

664-
if (inputSlot) {
665-
inputSlot.assignedNodes()[0].focus();
662+
const inputSlot = searchField.children[0];
663+
const input = inputSlot && inputSlot.assignedNodes()[0];
664+
665+
// update the state immediately
666+
if (input) {
667+
input.focused = true;
668+
}
669+
670+
// move the focus later
671+
setTimeout(() => {
672+
if (input) {
673+
input.focus();
666674
}
667675
}, 100);
668676
}

packages/fiori/test/pages/ShellBar.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@
120120
<ui5-shellbar-item id="disc" icon="disconnected" text="Disconnect"></ui5-shellbar-item>
121121
<ui5-shellbar-item id="call" icon="incoming-call" text="Incoming Calls"></ui5-shellbar-item>
122122

123-
<ui5-input slot="searchField"></ui5-input>
123+
<ui5-input placeholder="Instructions" slot="searchField" show-suggestions value-state="Information">
124+
<div slot="valueStateMessage">Instructions</div>
125+
</ui5-input>
124126

125127
<ui5-li id="menu-item-1" slot="menuItems" data-key="key1">Application 1</ui5-li>
126128
<ui5-li id="menu-item-2" slot="menuItems" data-key="key2">Application 2</ui5-li>
@@ -184,7 +186,8 @@ <h3>ShellBar in Compact</h3>
184186

185187

186188
<ui5-shellbar>
187-
<ui5-input id="mySearch" slot="searchField" show-suggestions>
189+
<ui5-input id="mySearch" slot="searchField" show-suggestions value-state="Information">
190+
<div slot="valueStateMessage">Instructions</div>
188191
<ui5-li icon="world" description="travel the world" info="explore" info-state="Success">1</ui5-li>
189192
<ui5-li icon="world" description="travel the world" info="explore" info-state="Success">2</ui5-li>
190193
<ui5-li icon="world" description="travel the world" info="explore" info-state="Success">3</ui5-li>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("Component Behavior", () => {
296296

297297
it("tests if searchfield toggles when clicking on search icon", () => {
298298
const searchIcon = browser.$("#shellbar").shadow$(".ui5-shellbar-search-button");
299-
const searchField = browser.$("#shellbar ui5-input");
299+
const searchField = browser.$("#shellbar").shadow$(".ui5-shellbar-search-field");
300300

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

@@ -379,7 +379,7 @@ describe("Component Behavior", () => {
379379

380380
it("tests if searchfield toggles when clicking on search icon", () => {
381381
const overflowButton = browser.$("#shellbar").shadow$(".ui5-shellbar-overflow-button");
382-
const searchField = browser.$("#shellbar ui5-input");
382+
const searchField = browser.$("#shellbar").shadow$(".ui5-shellbar-search-field");
383383
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#shellbar")
384384
const overflowPopover = browser.$(`.${staticAreaItemClassName}`).shadow$(".ui5-shellbar-overflow-popover");
385385
const searchListItem = overflowPopover.$("ui5-list ui5-li:nth-child(1)");

packages/main/src/Input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ class Input extends UI5Element {
479479

480480
if (!isPhone() && shouldOpenSuggestions) {
481481
// Set initial focus to the native input
482-
this.inputDomRef.focus();
482+
this.inputDomRef && this.inputDomRef.focus();
483483
}
484484
}
485485

@@ -545,7 +545,7 @@ class Input extends UI5Element {
545545
this.previousValue = this.value;
546546

547547
await this.getInputDOMRef();
548-
this._inputIconFocused = event.target === this.querySelector("ui5-icon");
548+
this._inputIconFocused = event.target && event.target === this.querySelector("ui5-icon");
549549
}
550550

551551
_onfocusout(event) {

0 commit comments

Comments
 (0)