Skip to content

Commit 5bfb097

Browse files
authored
fix(select): close menu when clicking on dropdown icon (#133)
1 parent 2267f53 commit 5bfb097

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Select.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ describe("input + menu interactions behavior", () => {
120120

121121
expect(wrapper.findAll("div[role='option']").length).toBe(0);
122122
});
123+
124+
it("should close the menu when clicking on the dropdown button", async () => {
125+
const wrapper = mount(VueSelect, { props: { modelValue: null, options } });
126+
127+
await openMenu(wrapper);
128+
129+
expect(wrapper.findAll("div[role='option']").length).toBe(options.length);
130+
131+
await wrapper.get(".dropdown-icon").trigger("click");
132+
133+
expect(wrapper.findAll("div[role='option']").length).toBe(0);
134+
});
123135
});
124136

125137
describe("menu on-open focus option", async () => {

src/Select.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ const closeMenu = () => {
183183
search.value = "";
184184
};
185185
186+
const toggleMenu = () => {
187+
if (menuOpen.value) {
188+
closeMenu();
189+
}
190+
else {
191+
openMenu();
192+
}
193+
};
194+
186195
const setOption = (option: GenericOption) => {
187196
if (option.disabled) {
188197
return;
@@ -453,7 +462,7 @@ onBeforeUnmount(() => {
453462
class="dropdown-icon"
454463
tabindex="-1"
455464
:disabled="isDisabled"
456-
@click="openMenu({ focusInput: true })"
465+
@click="toggleMenu"
457466
>
458467
<slot name="dropdown">
459468
<ChevronDownIcon />

0 commit comments

Comments
 (0)