Skip to content

Commit 2c033aa

Browse files
authored
fix(ui5-input): focus is handled properly (#2670)
1 parent b36e54e commit 2c033aa

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

packages/main/src/Input.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,7 @@ class Input extends UI5Element {
654654
}
655655

656656
async _onfocusin(event) {
657-
const inputDomRef = await this.getInputDOMRef();
658-
659-
if (event.target !== inputDomRef) {
660-
return;
661-
}
657+
await this.getInputDOMRef();
662658

663659
this.focused = true; // invalidating property
664660
this.previousValue = this.value;

packages/main/src/MultiInput.js

+11
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ class MultiInput extends Input {
237237
}
238238
}
239239

240+
/**
241+
* @override
242+
*/
243+
async _onfocusin(event) {
244+
const inputDomRef = await this.getInputDOMRef();
245+
246+
if (event.target === inputDomRef) {
247+
await super._onfocusin(event);
248+
}
249+
}
250+
240251
shouldOpenSuggestions() {
241252
const parent = super.shouldOpenSuggestions();
242253
const valueHelpPressed = this._valueHelpIconPressed;

packages/main/test/pages/Input.html

+15
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,22 @@ <h3>Test width of suggestions popover</h3>
295295
<ui5-li>Argentinaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</ui5-li>
296296
</ui5-input>
297297

298+
<h3>Input in a Dialog</h3>
299+
<ui5-button id="btnOpenDialog">Open Dialog</ui5-button>
300+
<ui5-dialog id="dialog">
301+
<ui5-input id="inputInDialog" show-suggestions style="width: 100%">
302+
<ui5-li>Cozy</ui5-li>
303+
<ui5-li>Compact</ui5-li>
304+
<ui5-li>Condensed</ui5-li>
305+
<ui5-li type="Inactive">Inactive Compact</ui5-li>
306+
<ui5-li type="Inactive">Inactive Condensed</ui5-li>
307+
</ui5-input>
308+
</ui5-dialog>
309+
298310
<script>
311+
btnOpenDialog.addEventListener("click", function () {
312+
dialog.open();
313+
});
299314
var sap_database_entries = [{ key: "A", text: "A" }, { key: "Afg", text: "Afghanistan" }, { key: "Arg", text: "Argentina" }, { key: "Alb", text: "Albania" }, { key: "Arm", text: "Armenia" }, { key: "Alg", text: "Algeria" }, { key: "And", text: "Andorra" }, { key: "Ang", text: "Angola" }, { key: "Ast", text: "Austria" }, { key: "Aus", text: "Australia" }, { key: "Aze", text: "Azerbaijan" }, { key: "Aruba", text: "Aruba" }, { key: "Antigua", text: "Antigua and Barbuda" }, { key: "B", text: "B" }, { key: "Bel", text: "Belarus" }, { key: "Bel", text: "Belgium" }, { key: "Bg", text: "Bulgaria" }, { key: "Bra", text: "Brazil" }, { key: "C", text: "C" }, { key: "Ch", text: "China" }, { key: "Cub", text: "Cuba" }, { key: "Chil", text: "Chili" }, { key: "L", text: "L" }, { key: "Lat", text: "Latvia" }, { key: "Lit", text: "Litva" }, { key: "P", text: "P" }, { key: "Prt", text: "Portugal" }, { key: "S", text: "S" }, { key: "Sen", text: "Senegal" }, { key: "Ser", text: "Serbia" }, { key: "Sey", text: "Seychelles" }, { key: "Sierra", text: "Sierra Leone" }, { key: "Sgp", text: "Singapore" }, { key: "Sint", text: "Sint Maarten" }, { key: "Slv", text: "Slovakia" }, { key: "Slo", text: "Slovenia" }];
300315

301316
var input = document.getElementById('myInput');

packages/main/test/specs/Input.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,19 @@ describe("Input general interaction", () => {
371371
assert.notOk(inputPopover.isDisplayedInViewport(), "The inpuit popover is closed as it lost the focus.");
372372
assert.ok(helpPopover.isDisplayedInViewport(), "The help popover remains open as the focus is within.");
373373
});
374+
375+
it("Should open suggestions popover when ui5-input is the first focusable element within a dialog", () => {
376+
browser.url("http://localhost:8080/test-resources/pages/Input.html");
377+
const input = $("#inputInDialog");
378+
const button = browser.$("#btnOpenDialog");
379+
380+
//act
381+
button.click();
382+
383+
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#inputInDialog");
384+
const popover = browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover");
385+
386+
//assert
387+
assert.ok(popover.isDisplayedInViewport(), "The popover is visible");
388+
});
374389
});

0 commit comments

Comments
 (0)