Skip to content

Commit a71ac05

Browse files
JesmoDevJesper Møller Jensen
andauthored
fix(uui-combobox): fix focus issues (#311)
* scroll-container. Only set tabindex if not already set * fixed focus issues * Fixed combobox closing when clickin inside Co-authored-by: Jesper Møller Jensen <[email protected]>
1 parent 7634d19 commit a71ac05

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

packages/uui-combobox/lib/uui-combobox.element.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
5858
box-shadow: var(--uui-shadow-depth-3);
5959
}
6060
61-
#clear-button {
62-
pointer-events: none;
63-
opacity: 0;
64-
transition: opacity 120ms;
65-
}
66-
67-
#clear-button.--show {
68-
pointer-events: auto;
69-
opacity: 1;
70-
}
71-
7261
#caret {
7362
margin-right: var(--uui-size-3, 9px);
7463
display: flex;
@@ -182,9 +171,10 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
182171
}
183172

184173
private _onMouseDown = () => requestAnimationFrame(() => this._input.focus());
174+
185175
private _onBlur = () =>
186176
requestAnimationFrame(() => {
187-
if (document.activeElement !== this) {
177+
if (!this.shadowRoot?.activeElement) {
188178
this._onClose();
189179
}
190180
});
@@ -250,6 +240,8 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
250240
// Reset input(search-input) value:
251241
this._input.value = this._displayValue;
252242

243+
this._input.focus();
244+
253245
this.dispatchEvent(new UUIComboboxEvent(UUIComboboxEvent.SEARCH));
254246
this.dispatchEvent(new UUIComboboxEvent(UUIComboboxEvent.CHANGE));
255247
};
@@ -278,22 +270,23 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
278270
};
279271

280272
private _renderClearButton = () => {
281-
return html`<uui-button
282-
id="clear-button"
283-
class=${this.value || this.search ? '--show' : ''}
284-
@click=${this._onClear}
285-
@keydown=${this._onClear}
286-
label="clear"
287-
slot="append"
288-
compact
289-
style="height: 100%;">
290-
<uui-icon name="remove" .fallback=${iconRemove.strings[0]}></uui-icon>
291-
</uui-button>`;
273+
return this.value || this.search
274+
? html`<uui-button
275+
id="clear-button"
276+
@click=${this._onClear}
277+
@keydown=${this._onClear}
278+
label="clear"
279+
slot="append"
280+
compact
281+
style="height: 100%;">
282+
<uui-icon name="remove" .fallback=${iconRemove.strings[0]}></uui-icon>
283+
</uui-button>`
284+
: '';
292285
};
293286

294287
private _renderDropdown = () => {
295288
return html`<div id="dropdown" slot="popover">
296-
<uui-scroll-container id="scroll-container">
289+
<uui-scroll-container tabindex="-1" id="scroll-container">
297290
<slot></slot>
298291
</uui-scroll-container>
299292
</div>`;

packages/uui-scroll-container/lib/uui-scroll-container.element.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export class UUIScrollContainerElement extends LitElement {
3636

3737
connectedCallback() {
3838
super.connectedCallback();
39-
this.setAttribute('tabindex', '0');
39+
if (!this.hasAttribute('tabindex')) {
40+
this.setAttribute('tabindex', '0');
41+
}
4042
}
4143
render() {
4244
return html`<slot></slot>`;

0 commit comments

Comments
 (0)