follow up to 10846

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

@ -2,4 +2,4 @@
"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 { is_array } from '../../../utils.js';
/**
* 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
var value = select.__value;
select_option(select, value, mounting);
if (select.multiple) {
var selected_options = [].map.call(select.querySelectorAll(':checked'), get_option_value);
if (is_array(value) && selected_options.every(e => value.includes)) {
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, {
childList: true
childList: true,
subtree: true
});
return () => {

Loading…
Cancel
Save