follow up to 10846

pull/10848/head
Dominic Gannaway 2 years ago
parent f5f9465edc
commit aa3bd9944a

@ -2,4 +2,4 @@
"svelte": patch "svelte": patch
--- ---
fix: ensure select value is updated upon select element removal fix: ensure select value is updated upon select option removal

@ -1,4 +1,5 @@
import { effect } from '../../../reactivity/effects.js'; import { effect } from '../../../reactivity/effects.js';
import { is_array } from '../../../utils.js';
/** /**
* Selects the correct option(s) (depending on whether this is a multiple select) * Selects the correct option(s) (depending on whether this is a multiple select)
@ -98,15 +99,23 @@ export function bind_select_value(select, get_value, update) {
// @ts-ignore // @ts-ignore
var value = select.__value; var value = select.__value;
select_option(select, value, mounting); select_option(select, value, mounting);
/** @type {HTMLOptionElement | null} */ if (select.multiple) {
var selected_option = select.querySelector(':checked'); var selected_options = [].map.call(select.querySelectorAll(':checked'), get_option_value);
if (selected_option === null || get_option_value(selected_option) !== value) { if (is_array(value) && selected_options.every(e => value.includes)) {
update(''); update(selected_options)
}
} else {
/** @type {HTMLOptionElement | null} */
var selected_option = select.querySelector(':checked');
if (selected_option === null || get_option_value(selected_option) !== value) {
update('');
}
} }
}); });
observer.observe(select, { observer.observe(select, {
childList: true childList: true,
subtree: true
}); });
return () => { return () => {

Loading…
Cancel
Save