Skip to content

Commit ea0ee09

Browse files
committed
fix: allow bind:this on <select> with dynamic multiple attribute
fixes #11377
1 parent 8b1a269 commit ea0ee09

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.changeset/healthy-ants-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: allow `bind:this` on `<select>` with dynamic `multiple` attribute

packages/svelte/src/compiler/phases/2-analyze/validation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ const validation = {
413413
}
414414
}
415415

416-
if (parent.name === 'select') {
416+
if (parent.name === 'select' && node.name !== 'this') {
417417
const multiple = parent.attributes.find(
418418
(a) =>
419419
a.type === 'Attribute' &&

packages/svelte/tests/validator/samples/binding-select-multiple-dynamic/errors.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"code": "attribute_invalid_multiple",
44
"message": "'multiple' attribute must be static if select uses two-way binding",
55
"start": {
6-
"line": 6,
6+
"line": 14,
77
"column": 19
88
},
99
"end": {
10-
"line": 6,
10+
"line": 14,
1111
"column": 29
1212
}
1313
}

packages/svelte/tests/validator/samples/binding-select-multiple-dynamic/input.svelte

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
let multiple;
44
</script>
55

6+
<!-- ok -->
7+
<select bind:this={value} {multiple}>
8+
<option>1</option>
9+
<option>2</option>
10+
<option>3</option>
11+
</select>
12+
13+
<!-- error -->
614
<select bind:value {multiple}>
715
<option>1</option>
816
<option>2</option>

0 commit comments

Comments
 (0)