Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
fix(AutoComplete): fix UX to open menu after autocomplete focus
Browse files Browse the repository at this point in the history
  • Loading branch information
lukicenturi committed Jun 25, 2024
1 parent 4d7bff9 commit 87decc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/components/forms/auto-complete/RuiAutoComplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ describe('autocomplete', () => {
},
});

await wrapper.find('input').trigger('focus');
await nextTick();
expect(document.body.querySelector('div[role=menu]')).toBeFalsy();

// Open Menu Select
await wrapper.find('[data-id=activator]').trigger('focus');
await wrapper.find('[data-id=activator]').trigger('click');
await vi.delay();
await nextTick();
Expand Down
9 changes: 7 additions & 2 deletions src/components/forms/auto-complete/RuiAutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ watch(anyFocused, (focused) => {
});
function onInputFocused() {
set(isOpen, true);
set(focusedValueIndex, -1);
if (get(shouldApplyValueAsSearch))
get(textInput)?.select();
Expand Down Expand Up @@ -460,7 +459,13 @@ function chipListener(item: (T extends string ? T : Record<K, T>), index: number
}
function onEnter(event: KeyboardEvent) {
if (get(filteredOptions).length > 0 && get(highlightedIndex) > -1 && get(isOpen)) {
if (!get(isOpen)) {
set(isOpen, true);
event.preventDefault();
return;
}
if (get(filteredOptions).length > 0 && get(highlightedIndex) > -1) {
applyHighlighted();
event.preventDefault();
}
Expand Down

0 comments on commit 87decc5

Please sign in to comment.