|
182 | 182 | }
|
183 | 183 |
|
184 | 184 | let option_msg_is_active = $state(false) // controls active state of <li>{createOptionMsg}</li>
|
185 |
| - let window_width = $state<number>() |
| 185 | + let window_width = $state(0) |
186 | 186 |
|
187 | 187 | // options matching the current search text
|
188 | 188 | $effect.pre(() => {
|
|
206 | 206 |
|
207 | 207 | // add an option to selected list
|
208 | 208 | function add(option: Option, event: Event) {
|
| 209 | + event.stopPropagation() |
209 | 210 | if (maxSelect && maxSelect > 1 && selected.length >= maxSelect) wiggle = true
|
210 | 211 | if (!isNaN(Number(option)) && typeof selected.map(get_label)[0] === `number`) {
|
211 | 212 | option = Number(option) as Option // convert to number if possible
|
|
348 | 349 | event.preventDefault() // prevent enter key from triggering form submission
|
349 | 350 |
|
350 | 351 | if (activeOption) {
|
351 |
| - if (selected.includes(activeOption)) remove(activeOption) |
| 352 | + if (selected.includes(activeOption)) remove(activeOption, event) |
352 | 353 | else add(activeOption, event)
|
353 | 354 | searchText = ``
|
354 | 355 | } else if (allowUserOptions && searchText.length > 0) {
|
|
398 | 399 | else if (event.key === `Backspace` && selected.length > 0 && !searchText) {
|
399 | 400 | event.stopPropagation()
|
400 | 401 | // Don't prevent default, allow normal backspace behavior if not removing
|
401 |
| - remove(selected.at(-1) as Option) |
| 402 | + remove(selected.at(-1) as Option, event) |
402 | 403 | }
|
403 | 404 | // make first matching option active on any keypress (if none of the above special cases match)
|
404 | 405 | else if (matchingOptions.length > 0 && activeIndex === null) {
|
|
580 | 581 | {/if}
|
581 | 582 | {#if !disabled && (minSelect === null || selected.length > minSelect)}
|
582 | 583 | <button
|
583 |
| - onmouseup={(event) => remove(option, event)} |
| 584 | + onclick={(event) => remove(option, event)} |
584 | 585 | onkeydown={if_enter_or_space((event) => remove(option, event))}
|
585 | 586 | type="button"
|
586 | 587 | title="{removeBtnTitle} {get_label(option)}"
|
|
660 | 661 | type="button"
|
661 | 662 | class="remove remove-all"
|
662 | 663 | title={removeAllTitle}
|
663 |
| - onmouseup={remove_all} |
| 664 | + onclick={remove_all} |
664 | 665 | onkeydown={if_enter_or_space(remove_all)}
|
665 | 666 | >
|
666 | 667 | {#if removeIcon}
|
|
0 commit comments