mirror of https://github.com/sveltejs/svelte
Merge f9d9682939 into 020242d6be
commit
d81dc78fe0
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: keep nullish `value` of spread `<option>` for `bind:value`
|
||||
@ -0,0 +1,19 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, target }) {
|
||||
const select = /** @type {HTMLSelectElement} */ (target.querySelector('select'));
|
||||
const p = /** @type {HTMLParagraphElement} */ (target.querySelector('p'));
|
||||
|
||||
select.selectedIndex = 1;
|
||||
select.dispatchEvent(new Event('change'));
|
||||
flushSync();
|
||||
assert.equal(p.textContent, 'undefined undefined');
|
||||
|
||||
select.selectedIndex = 2;
|
||||
select.dispatchEvent(new Event('change'));
|
||||
flushSync();
|
||||
assert.equal(p.textContent, 'object null');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
let value = $state('a');
|
||||
const options = [
|
||||
{ value: 'a', label: 'a' },
|
||||
{ value: undefined, label: 'undefined' },
|
||||
{ value: null, label: 'null' }
|
||||
];
|
||||
</script>
|
||||
|
||||
<select bind:value>
|
||||
{#each options as { value, label, ...rest }}
|
||||
<option {value} {...rest}>{label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<p>{typeof value} {String(value)}</p>
|
||||
Loading…
Reference in new issue