|
118 | 118 |
|
119 | 119 | // Capture for next change
|
120 | 120 | prevValue = selected?.value;
|
121 |
| - prevSelected = selectOption(selected); |
| 121 | + // Do not close menu when selection is updated reactively |
| 122 | + prevSelected = selectOption(selected, false); |
122 | 123 | } else if (/*value !== undefined &&*/ value !== prevValue) {
|
123 | 124 | // Removed `value !== undefined` to clear searchText when value is set to undefined. Might be a breaking change
|
124 | 125 | logger.info('value changed', {
|
|
131 | 132 |
|
132 | 133 | // Capture for next change
|
133 | 134 | prevValue = value;
|
134 |
| - prevSelected = selectValue(value); |
| 135 | + prevSelected = selectValue(value, false); |
135 | 136 | } else {
|
136 | 137 | logger.info('neither selected or value changed (options only)');
|
137 | 138 | // Reselect value if menu is not open and options possibly changed (which could result in new display text for the select value)
|
|
358 | 359 | /**
|
359 | 360 | * Select option by value
|
360 | 361 | */
|
361 |
| - function selectValue(value: TValue | null | undefined) { |
| 362 | + function selectValue(value: TValue | null | undefined, closeMenu: boolean = true) { |
362 | 363 | logger.debug('selectValue', { value, options, filteredOptions });
|
363 | 364 |
|
364 | 365 | const option = options?.find((option) => option.value === value) ?? null;
|
365 |
| - return selectOption(option); |
| 366 | + return selectOption(option, closeMenu); |
366 | 367 | }
|
367 | 368 |
|
368 | 369 | /**
|
369 | 370 | * Select option by object
|
370 | 371 | */
|
371 |
| - function selectOption(option: MenuOption<TValue> | null) { |
| 372 | + function selectOption(option: MenuOption<TValue> | null, closeMenu: boolean = true) { |
372 | 373 | logger.info('selectOption', { option });
|
373 | 374 |
|
374 | 375 | const previousValue = value;
|
|
389 | 390 | dispatch('change', { option, value });
|
390 | 391 | }
|
391 | 392 |
|
392 |
| - hide('selectOption'); |
| 393 | + if (closeMenu) { |
| 394 | + hide('selectOption'); |
| 395 | + } |
393 | 396 |
|
394 | 397 | return option;
|
395 | 398 | }
|
|
418 | 421 |
|
419 | 422 | function clear() {
|
420 | 423 | logger.info('clear');
|
421 |
| - selectOption(null); |
| 424 | + // Clearing should not close the menu🤞; keep it open if it already is |
| 425 | + selectOption(null, false); |
422 | 426 | filteredOptions = options;
|
423 | 427 | }
|
424 | 428 | </script>
|
|
0 commit comments