Skip to content

Commit 9e5fe33

Browse files
committed
fix: update error message to clarify usage with radio inputs
1 parent e9cd45a commit 9e5fe33

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

.changeset/slow-nails-push.md

Lines 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: update `bind:checked` error message to clarify usage with radio inputs

documentation/docs/03-template-syntax/12-bind.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Since 5.6.0, if an `<input>` has a `defaultValue` and is part of a form, it will
9595
9696
## `<input bind:checked>`
9797

98-
Checkbox and radio inputs can be bound with `bind:checked`:
98+
Checkbox can be bound with `bind:checked`:
9999

100100
```svelte
101101
<label>
@@ -117,6 +117,8 @@ Since 5.6.0, if an `<input>` has a `defaultChecked` attribute and is part of a f
117117
</form>
118118
```
119119

120+
> [!NOTE] Use `group:bind` for radio inputs instead of `bind:checked`.
121+
120122
## `<input bind:indeterminate>`
121123

122124
Checkboxes can be in an [indeterminate](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/indeterminate) state, independently of whether they are checked or unchecked:

packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export function BindDirective(node, context) {
6767
}
6868
} else {
6969
if (node.name === 'checked' && type?.value[0].data !== 'checkbox') {
70-
e.bind_invalid_target(node, node.name, '<input type="checkbox">');
70+
e.bind_invalid_target(
71+
node,
72+
node.name,
73+
`<input type="checkbox"> - for <input type="radio">, use 'group' binding`
74+
);
7175
}
7276

7377
if (node.name === 'files' && type?.value[0].data !== 'file') {

packages/svelte/tests/validator/samples/binding-input-checked/errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"code": "bind_invalid_target",
4-
"message": "`bind:checked` can only be used with <input type=\"checkbox\">",
4+
"message": "`bind:checked` can only be used with <input type=\"checkbox\"> - for <input type=\"radio\">, use 'group' binding",
55
"start": {
66
"line": 5,
77
"column": 7

0 commit comments

Comments
 (0)