Skip to content

Commit 66b6244

Browse files
authored
fix: allow boolean contenteditable attribute (#10590)
fixes #10559
1 parent 5800847 commit 66b6244

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

.changeset/spotty-turkeys-sparkle.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: allow boolean `contenteditable` attribute

packages/svelte/src/compiler/errors.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ const errors = {
371371
// message:
372372
// "'contenteditable' attribute is required for textContent, innerHTML and innerText two-way bindings"
373373
// },
374-
// dynamic_contenteditable_attribute: {
375-
// code: 'dynamic-contenteditable-attribute',
376-
// message: "'contenteditable' attribute cannot be dynamic if element uses two-way binding"
377-
// },
378374
// textarea_duplicate_value: {
379375
// code: 'textarea-duplicate-value',
380376
// message:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ const validation = {
475475
);
476476
if (!contenteditable) {
477477
error(node, 'missing-contenteditable-attribute');
478-
} else if (!is_text_attribute(contenteditable)) {
478+
} else if (!is_text_attribute(contenteditable) && contenteditable.value !== true) {
479479
error(contenteditable, 'dynamic-contenteditable-attribute');
480480
}
481481
}

packages/svelte/tests/validator/samples/contenteditable-dynamic/errors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"code": "dynamic-contenteditable-attribute",
44
"message": "'contenteditable' attribute cannot be dynamic if element uses two-way binding",
55
"start": {
6-
"line": 6,
6+
"line": 11,
77
"column": 8
88
},
99
"end": {
10-
"line": 6,
10+
"line": 11,
1111
"column": 32
1212
}
1313
}

packages/svelte/tests/validator/samples/contenteditable-dynamic/input.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
44
let toggle = false;
55
</script>
6+
<!-- ok -->
7+
<editor contenteditable="true" bind:innerHTML={name}></editor>
8+
<editor contenteditable="" bind:innerHTML={name}></editor>
9+
<editor contenteditable bind:innerHTML={name}></editor>
10+
<!-- error -->
611
<editor contenteditable={toggle} bind:innerHTML={name}></editor>

0 commit comments

Comments
 (0)