Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/uui-combobox-list/lib/uui-combobox-list.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class UUIComboboxListElement extends LitElement {
private _onKeyDown = (e: KeyboardEvent) => {
if (this._options.length <= 0) return;

switch (e.key) {
switch (e.code) {
case 'ArrowUp':
e.preventDefault();
if (e.ctrlKey) {
Expand Down Expand Up @@ -239,6 +239,14 @@ export class UUIComboboxListElement extends LitElement {
break;
}

//Space key
case 'Space': {
e.preventDefault();
e.stopPropagation();
this._getActiveElement?.click();
break;
}

case 'End': {
e.preventDefault();
this._goToIndex(this._options.length - 1);
Expand Down
13 changes: 10 additions & 3 deletions packages/uui-combobox/lib/uui-combobox.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,23 @@ export class UUIComboboxElement extends UUIFormControlMixin(LitElement, '') {
};

#onKeyDown = (e: KeyboardEvent) => {
if (this.open === false && e.key === 'Enter') {
if (this.open === false && e.code === 'Enter') {
e.preventDefault(); // TODO: could we avoid this.
e.stopImmediatePropagation(); // TODO: could we avoid this.
}

if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
if (e.code === 'ArrowUp' || e.code === 'ArrowDown') {
this.#onOpen();
}

if (e.key === 'Escape' || e.key === 'Enter') {
if (e.code === 'Space') {
if (this._isOpen) return;
e.preventDefault();
e.stopImmediatePropagation();
this.#onOpen();
}

if (e.code === 'Escape' || e.code === 'Enter') {
this.#onClose();
}
};
Expand Down
8 changes: 6 additions & 2 deletions packages/uui-combobox/lib/uui-combobox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ describe('UUIComboboxElement', () => {

describe('keyboard navigation', () => {
it('moves `active`-focus to second option on pressing the arrow down key', async () => {
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }));
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }));
element.dispatchEvent(
new KeyboardEvent('keydown', { key: 'ArrowDown', code: 'ArrowDown' }),
);
element.dispatchEvent(
new KeyboardEvent('keydown', { key: 'ArrowDown', code: 'ArrowDown' }),
);

await elementUpdated(element);

Expand Down
Loading