Skip to content

Commit e211227

Browse files
authored
fix(ui5-combobox): component improvements (#1141)
1 parent 7c4ee77 commit e211227

File tree

3 files changed

+53
-30
lines changed

3 files changed

+53
-30
lines changed

packages/main/src/ComboBox.hbs

+28-28
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,6 @@
44
aria-expanded="{{open}}"
55
>
66

7-
<input id="ui5-combobox-input"
8-
.value="{{_tempValue}}"
9-
inner-input
10-
placeholder="{{placeholder}}"
11-
?disabled={{disabled}}
12-
?readonly={{readonly}}
13-
?required={{required}}
14-
value-state="{{valueState}}"
15-
@input="{{_input}}"
16-
@change="{{_inputChange}}"
17-
@keydown="{{_keydown}}"
18-
@focusin="{{_focusin}}"
19-
@focusout="{{_focusout}}"
20-
aria-autocomplete="both"
21-
/>
22-
23-
{{#unless readonly}}
24-
<ui5-icon
25-
name="slim-arrow-down"
26-
slot="icon"
27-
tabindex="-1"
28-
input-icon
29-
?pressed="{{_iconPressed}}"
30-
@click="{{_arrowClick}}"
31-
dir="{{dir}}"
32-
></ui5-icon>
33-
{{/unless}}
34-
357
<ui5-popover
368
class="ui5-combobox-popover"
379
style={{styles.popover}}
@@ -40,6 +12,7 @@
4012
no-padding="true"
4113
placement-type="Bottom"
4214
initial-focus="ui5-combobox-input"
15+
tabindex="-1"
4316
@ui5-afterOpen={{_afterOpenPopover}}
4417
@ui5-afterClose={{_afterClosePopover}}
4518
>
@@ -68,4 +41,31 @@
6841
</ui5-list>
6942
</ui5-popover>
7043

44+
<input id="ui5-combobox-input"
45+
.value="{{_tempValue}}"
46+
inner-input
47+
placeholder="{{placeholder}}"
48+
?disabled={{disabled}}
49+
?readonly={{readonly}}
50+
?required={{required}}
51+
value-state="{{valueState}}"
52+
@input="{{_input}}"
53+
@change="{{_inputChange}}"
54+
@keydown="{{_keydown}}"
55+
@focusin="{{_focusin}}"
56+
@focusout="{{_focusout}}"
57+
aria-autocomplete="both"
58+
/>
59+
60+
{{#unless readonly}}
61+
<ui5-icon
62+
name="slim-arrow-down"
63+
slot="icon"
64+
tabindex="-1"
65+
input-icon
66+
?pressed="{{_iconPressed}}"
67+
@click="{{_arrowClick}}"
68+
dir="{{dir}}"
69+
></ui5-icon>
70+
{{/unless}}
7171
</div>

packages/main/src/ComboBox.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
4+
import "@ui5/webcomponents-icons/dist/icons/slim-arrow-down.js";
45
import { isBackSpace, isDelete, isShow } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
56
import * as Filters from "./ComboBoxFilters.js";
67

@@ -11,6 +12,8 @@ import ComboBoxItem from "./ComboBoxItem.js";
1112
import Icon from "./Icon.js";
1213
import Popover from "./Popover.js";
1314
import List from "./List.js";
15+
import BusyIndicator from "./BusyIndicator.js";
16+
import StandardListItem from "./StandardListItem.js";
1417

1518
const metadata = {
1619
tag: "ui5-combobox",
@@ -253,19 +256,35 @@ class ComboBox extends UI5Element {
253256

254257
this._filteredItems = [];
255258
this._initialRendering = true;
259+
260+
this.addEventListener("focusout", () => {
261+
if (this.popover) {
262+
this.popover.close();
263+
}
264+
});
256265
}
257266

258267
onBeforeRendering() {
259268
const domValue = this._initialRendering ? this.value : this.filterValue;
260269

261270
this._filteredItems = this._filterItems(domValue);
262271

272+
// prevent popover focus restore
273+
// TODO: fix that once popovers are fixed to static area
274+
if (this.popover) {
275+
this.popover._prevetFocusRestore = true;
276+
}
277+
263278
if (this._autocomplete && domValue !== "") {
264279
this._autoCompleteValue(domValue);
265280
} else {
266281
this._tempValue = domValue;
267282
}
268283

284+
if (this.popover && document.activeElement === this && !this._filteredItems.length) {
285+
this.popover.close();
286+
}
287+
269288
this._selectMatchingItem();
270289
this._initialRendering = false;
271290
}
@@ -358,7 +377,7 @@ class ComboBox extends UI5Element {
358377
this._tempValue = current;
359378
}
360379

361-
if (matchingItems.length) {
380+
if (matchingItems.length && (currentValue !== this._tempValue)) {
362381
setTimeout(() => {
363382
this.inner.setSelectionRange(currentValue.length, this._tempValue.length);
364383
}, 0);
@@ -428,6 +447,8 @@ class ComboBox extends UI5Element {
428447
Icon.define(),
429448
Popover.define(),
430449
List.define(),
450+
BusyIndicator.define(),
451+
StandardListItem.define(),
431452
]);
432453

433454
super.define(...params);

packages/main/src/Popover.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ class Popover extends UI5Element {
343343
removeOpenedPopover(this);
344344
}
345345

346-
this.resetFocus();
346+
if (!this._prevetFocusRestore) {
347+
this.resetFocus();
348+
}
347349

348350
this.hide();
349351
this.fireEvent("afterClose", {});

0 commit comments

Comments
 (0)