File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ function openMenu() {
126126function 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
252256watch (
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
264270watch (
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 }
You can’t perform that action at this time.
0 commit comments