forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: select option with selected attribute when initial state is unde…
…fined (sveltejs#8371) Resolves a second unintended regression introduced in sveltejs#6170. Follow-up to sveltejs#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 sveltejs#8361
- Loading branch information
1 parent
5c14bc5
commit c7dcfac
Showing
4 changed files
with
49 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/runtime/samples/binding-select-initial-value-undefined-2/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |
13 changes: 13 additions & 0 deletions
13
test/runtime/samples/binding-select-initial-value-undefined-2/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |