fix: only `select_option` if `'value'` is in `next` (#16032)

pull/16033/head
Paolo Ricciuti 3 months ago committed by GitHub
parent 0d67ff4865
commit c9ce4f439f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: only `select_option` if `'value'` is in `next`

@ -486,7 +486,7 @@ export function attribute_effect(
set_attributes(element, prev, next, css_hash, skip_warning);
if (inited && is_select) {
if (inited && is_select && 'value' in next) {
select_option(/** @type {HTMLSelectElement} */ (element), next.value, false);
}

@ -0,0 +1,20 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
async test({ assert, target }) {
const select = target.querySelector('select');
ok(select);
const [option1, option2] = select;
assert.ok(option1.selected);
assert.ok(!option2.selected);
const btn = target.querySelector('button');
flushSync(() => {
btn?.click();
});
assert.ok(option1.selected);
assert.ok(!option2.selected);
}
});

@ -0,0 +1,10 @@
<script>
let { value = "Hello", spread = { disabled: false } } = $props();
</script>
<button onclick={()=> spread = { disabled: false }}></button>
<select bind:value {...spread}>
<option>Hello</option>
<option>World</option>
</select>
Loading…
Cancel
Save