Skip to content

Commit 71ad253

Browse files
committed
fix(select): prevent closeMenu to be called on mounted
1 parent 8d0aa8a commit 71ad253

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Select.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function openMenu() {
126126
function closeMenu() {
127127
menuOpen.value = false;
128128
search.value = "";
129+
emit("search", "");
129130
emit("menuClosed");
130131
};
131132
@@ -207,7 +208,9 @@ const clear = () => {
207208
emit("optionDeselected", selectedOptions.value[0]);
208209
}
209210
210-
closeMenu();
211+
if (menuOpen.value) {
212+
closeMenu();
213+
}
211214
212215
if (inputRef.value) {
213216
inputRef.value.blur();
@@ -249,21 +252,29 @@ provide(DATA_KEY, {
249252
createOption,
250253
});
251254
255+
// Watch the search input value to emit search events and auto-open the menu when typing
252256
watch(
253257
() => search.value,
254258
() => {
255-
emit("search", search.value);
259+
if (search.value) {
260+
emit("search", search.value);
256261
257-
// When starting to type, open the menu automatically.
258-
if (search.value && !menuOpen.value) {
259-
openMenu();
262+
if (!menuOpen.value) {
263+
openMenu();
264+
}
260265
}
261266
},
262267
);
263268
269+
// Watch the isMenuOpen prop to allow external control of the dropdown menu visibility
264270
watch(
265271
() => props.isMenuOpen,
266-
(newValue) => {
272+
(newValue, oldValue) => {
273+
// Skip the initial call when the component is mounted
274+
if (oldValue === undefined && newValue === undefined) {
275+
return;
276+
}
277+
267278
if (newValue) {
268279
openMenu();
269280
}

0 commit comments

Comments
 (0)