Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix select bind:value when option value change #4885

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Update `<select>` with `bind:value` when the available `<option>`s change ([#1764](https://github.com/sveltejs/svelte/issues/1764))
* Fix inconsistencies when setting a two-way bound `<input>` to `undefined` ([#3569](https://github.com/sveltejs/svelte/issues/3569))
* Fix resize listening on certain older browsers ([#4752](https://github.com/sveltejs/svelte/issues/4752))
* Add `a11y-no-onchange` warning ([#4788](https://github.com/sveltejs/svelte/pull/4788))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class BindingWrapper {
const update_conditions: any[] = this.needs_lock ? [x`!${lock}`] : [];
const mount_conditions: any[] = [];

const dependency_array = [...this.node.expression.dependencies];
const dependency_array = Array.from(this.get_dependencies());

if (dependency_array.length > 0) {
update_conditions.push(block.renderer.dirty(dependency_array));
Expand Down
34 changes: 34 additions & 0 deletions test/runtime/samples/binding-select-late-2/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export default {
props: {
items: [],
selected: 'two'
},

html: `
<select></select>
<p>selected: two</p>
`,

ssrHtml: `
<select value="two"></select>
<p>selected: two</p>
`,

test({ assert, component, target }) {
component.items = [ 'one', 'two', 'three' ];

const options = target.querySelectorAll('option');
assert.ok(!options[0].selected);
assert.ok(options[1].selected);
assert.ok(!options[2].selected);

assert.htmlEqual(target.innerHTML, `
<select>
<option value='one'>one</option>
<option value='two'>two</option>
<option value='three'>three</option>
</select>
<p>selected: two</p>
`);
}
};
12 changes: 12 additions & 0 deletions test/runtime/samples/binding-select-late-2/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
export let selected;
export let items;
</script>

<select bind:value={selected}>
{#each items as item}
<option>{item}</option>
{/each}
</select>

<p>selected: {selected || 'nothing'}</p>