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
Original file line number Diff line number Diff line change
Expand Up @@ -1077,4 +1077,26 @@ describe('components/forms/auto-complete/RuiAutoComplete.vue', () => {
const chipElement = firstChip.element as HTMLElement;
expect(chipElement.getAttribute('data-index')).toBe('0');
});

it('should expose openMenu and closeMenu to control the menu programmatically', async () => {
wrapper = createWrapper<string | undefined, SelectOption>({
props: {
keyAttr: 'id',
modelValue: undefined,
options,
textAttr: 'label',
},
});

await vi.advanceTimersToNextTimerAsync();
expect(queryByRole('menu')).toBeFalsy();

wrapper.vm.openMenu();
await vi.runAllTimersAsync();
expect(queryByRole('menu')).toBeTruthy();

wrapper.vm.closeMenu();
await vi.runAllTimersAsync();
expect(queryByRole('menu')).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ function arrowClicked(event: MouseEvent): void {
}
}

function openMenu(): void {
set(isOpen, true);
}

function closeMenu(): void {
set(isOpen, false);
}

// Optimize options watcher with shallow comparison first
watch(() => options, (curr, old) => {
if (curr === old || customValue)
Expand All @@ -438,7 +446,9 @@ watch(() => options, (curr, old) => {
});

defineExpose({
closeMenu,
focus: focusSetInputFocus,
openMenu,
setSelectionRange,
});
</script>
Expand Down
Loading