Skip to content

Commit 5adbbe1

Browse files
committed
fix: don't open menu when is-disabled and a value is pre-selected
closes #88
1 parent f45c845 commit 5adbbe1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Select.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ const options = [
1010
{ label: "Germany", value: "DE" },
1111
];
1212

13-
async function openMenu(wrapper: ReturnType<typeof mount>, method: "mousedown" | "focus-space" = "mousedown") {
13+
async function openMenu(wrapper: ReturnType<typeof mount>, method: "mousedown" | "focus-space" | "single-value" = "mousedown") {
1414
if (method === "mousedown") {
1515
await wrapper.get("input").trigger("mousedown");
1616
}
17-
else {
17+
else if (method === "focus-space") {
1818
await wrapper.get("input").trigger("focus");
1919
await wrapper.get("input").trigger("keydown", { key: "Space" });
2020
}
21+
else if (method === "single-value") {
22+
await wrapper.get(".single-value").trigger("click");
23+
}
2124
}
2225

2326
async function dispatchEvent(wrapper: ReturnType<typeof mount>, event: Event) {
@@ -74,6 +77,14 @@ describe("input + menu interactions behavior", () => {
7477
expect(wrapper.findAll("div[role='option']").length).toBe(options.length);
7578
});
7679

80+
it("should not open the menu when is-disabled and an option is selected", async () => {
81+
const wrapper = mount(VueSelect, { props: { modelValue: options[0].value, options, isDisabled: true } });
82+
83+
await openMenu(wrapper, "single-value");
84+
85+
expect(wrapper.findAll("div[role='option']").length).toBe(0);
86+
});
87+
7788
it("should close the menu after focusing and pressing tab", async () => {
7889
const wrapper = mount(VueSelect, { props: { modelValue: null, options } });
7990

src/Select.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ onBeforeUnmount(() => {
384384
<div
385385
v-if="!props.isMulti && selectedOptions[0]"
386386
class="single-value"
387-
@click="openMenu({ focusInput: true })"
387+
@click="!props.isDisabled ? openMenu({ focusInput: true }) : null"
388388
>
389389
<slot name="value" :option="selectedOptions[0]">
390390
{{ getOptionLabel(selectedOptions[0]) }}

0 commit comments

Comments
 (0)