mirror of https://github.com/sveltejs/svelte
fix: select option with selected attribute when initial state is undefined (#8371)
Resolves a second unintended regression introduced in #6170. Follow-up to #8331, this time addressing the root issue so the correct select option won't be deselected in the first place when the initial bound value is undefined. Fixes #8361pull/8382/head
parent
5c14bc5f01
commit
c7dcfac883
@ -0,0 +1,25 @@
|
|||||||
|
export default {
|
||||||
|
skip_if_ssr: true, // TODO would be nice to fix this in SSR as well
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<p>selected: b</p>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value='a'>a</option>
|
||||||
|
<option value='b'>b</option>
|
||||||
|
<option value='c'>c</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<p>selected: b</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test({ assert, component, target }) {
|
||||||
|
assert.equal(component.selected, 'b');
|
||||||
|
const select = target.querySelector('select');
|
||||||
|
const options = [...target.querySelectorAll('option')];
|
||||||
|
|
||||||
|
// option with selected attribute should be selected
|
||||||
|
assert.equal(select.value, 'b');
|
||||||
|
assert.ok(options[1].selected);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
export let selected;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>selected: {selected}</p>
|
||||||
|
|
||||||
|
<select bind:value={selected}>
|
||||||
|
<option>a</option>
|
||||||
|
<option selected>b</option>
|
||||||
|
<option>c</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<p>selected: {selected}</p>
|
Loading…
Reference in new issue