Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9ce4f4

Browse filesBrowse files
fix: only select_option if 'value' is in next (#16032)
1 parent 0d67ff4 commit c9ce4f4
Copy full SHA for c9ce4f4

File tree

Expand file treeCollapse file tree

4 files changed

+36
-1
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-1
lines changed

‎.changeset/smooth-weeks-hide.md

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: only `select_option` if `'value'` is in `next`

‎packages/svelte/src/internal/client/dom/elements/attributes.js

Copy file name to clipboardExpand all lines: packages/svelte/src/internal/client/dom/elements/attributes.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ export function attribute_effect(
486486

487487
set_attributes(element, prev, next, css_hash, skip_warning);
488488

489-
if (inited && is_select) {
489+
if (inited && is_select && 'value' in next) {
490490
select_option(/** @type {HTMLSelectElement} */ (element), next.value, false);
491491
}
492492

+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { flushSync } from 'svelte';
2+
import { ok, test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target }) {
6+
const select = target.querySelector('select');
7+
ok(select);
8+
const [option1, option2] = select;
9+
10+
assert.ok(option1.selected);
11+
assert.ok(!option2.selected);
12+
13+
const btn = target.querySelector('button');
14+
flushSync(() => {
15+
btn?.click();
16+
});
17+
assert.ok(option1.selected);
18+
assert.ok(!option2.selected);
19+
}
20+
});
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
let { value = "Hello", spread = { disabled: false } } = $props();
3+
</script>
4+
5+
<button onclick={()=> spread = { disabled: false }}></button>
6+
7+
<select bind:value {...spread}>
8+
<option>Hello</option>
9+
<option>World</option>
10+
</select>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.