don't update value

pull/10848/head
Simon Holthausen 2 years ago
parent e10c91e1b1
commit b1a23c395e

@ -99,21 +99,13 @@ 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);
update(selected_options);
} else {
/** @type {HTMLOptionElement | null} */
var selected_option = select.querySelector(':checked');
if (selected_option === null || get_option_value(selected_option) !== value) {
update('');
}
}
// Deliberately don't update the binding value,
// the model should be preserved unless explicitly changed
});
observer.observe(select, {
childList: true,
subtree: true
subtree: true // because of <optgroup>
});
return () => {

@ -26,9 +26,10 @@ export default test({
assert.equal(select.value, '');
assert.equal(select.selectedIndex, -1);
// model of selected value should be kept around, even if it is not in the list
assert.htmlEqual(
target.innerHTML,
`<p>selected:</p><select><option value="b">b</option><option value="c">c</option></select>`
`<p>selected: a</p><select><option value="b">b</option><option value="c">c</option></select>`
);
}
});

Loading…
Cancel
Save