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
12 changes: 12 additions & 0 deletions src/Select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ describe("input + menu interactions behavior", () => {

expect(wrapper.findAll("div[role='option']").length).toBe(0);
});

it("should close the menu when clicking on the dropdown button", async () => {
const wrapper = mount(VueSelect, { props: { modelValue: null, options } });

await openMenu(wrapper);

expect(wrapper.findAll("div[role='option']").length).toBe(options.length);

await wrapper.get(".dropdown-icon").trigger("click");

expect(wrapper.findAll("div[role='option']").length).toBe(0);
});
});

describe("menu on-open focus option", async () => {
Expand Down
11 changes: 10 additions & 1 deletion src/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ const closeMenu = () => {
search.value = "";
};

const toggleMenu = () => {
if (menuOpen.value) {
closeMenu();
}
else {
openMenu();
}
};

const setOption = (option: GenericOption) => {
if (option.disabled) {
return;
Expand Down Expand Up @@ -453,7 +462,7 @@ onBeforeUnmount(() => {
class="dropdown-icon"
tabindex="-1"
:disabled="isDisabled"
@click="openMenu({ focusInput: true })"
@click="toggleMenu"
>
<slot name="dropdown">
<ChevronDownIcon />
Expand Down