mirror of https://github.com/sveltejs/svelte
fix: make `<select>` `<option value>` behavior consistent (#12316)
Setting the `value` attribute of an `<option>` element to a falsy value should result in the empty string. This wasn't happening in all situations previously. Fixes #11616pull/12353/head
parent
ba93e5fce3
commit
63f3ee4ffd
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: make `<select>` `<option value>` behavior consistent
|
@ -0,0 +1,32 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// <option value> is special because falsy values should result in an empty string value attribute
|
||||||
|
export default test({
|
||||||
|
mode: ['client'],
|
||||||
|
test({ assert, target }) {
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<select>
|
||||||
|
<option value="">Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value="">Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value="">Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value="">Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value="">Default</option>
|
||||||
|
</select>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,26 @@
|
|||||||
|
<script>
|
||||||
|
let nonreactive = undefined;
|
||||||
|
let reactive = $state();
|
||||||
|
let nonreactive_spread = { value: undefined };
|
||||||
|
let reactive_spread = $state({ value: undefined });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value={undefined}>Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value={nonreactive}>Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option value={reactive}>Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option {...nonreactive_spread}>Default</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select>
|
||||||
|
<option {...reactive_spread}>Default</option>
|
||||||
|
</select>
|
Loading…
Reference in new issue