From bdc815462c9351523d8b5acc570980be77eb27a5 Mon Sep 17 00:00:00 2001 From: Bassam Ismail Date: Mon, 15 Jun 2020 23:18:05 +0530 Subject: [PATCH 1/3] fix(5020): skip child content a11y check on html/textContent binding --- src/compiler/compile/nodes/Element.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 517ed3ceb679..8ca54b004b29 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -706,6 +706,11 @@ export default class Element extends Node { validate_content() { if (!a11y_required_content.has(this.name)) return; + if ( + this.bindings + .map((binding) => binding.name) + .some((name) => ['textContent', 'innerHTML'].includes(name)) + ) return; if (this.children.length === 0) { this.component.warn(this, { From 3d6baf5dd50da2989b071e2636d34780cbbafa43 Mon Sep 17 00:00:00 2001 From: Bassam Ismail Date: Tue, 23 Jun 2020 20:20:44 +0530 Subject: [PATCH 2/3] fix(5020): add tests to validate error isn't thrown when contenteditable is added --- .../errors.json | 17 +++++++++++++++++ .../input.svelte | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 test/validator/samples/a11y-contenteditable-element-without-child/errors.json create mode 100644 test/validator/samples/a11y-contenteditable-element-without-child/input.svelte diff --git a/test/validator/samples/a11y-contenteditable-element-without-child/errors.json b/test/validator/samples/a11y-contenteditable-element-without-child/errors.json new file mode 100644 index 000000000000..dd2a915b9d91 --- /dev/null +++ b/test/validator/samples/a11y-contenteditable-element-without-child/errors.json @@ -0,0 +1,17 @@ +[ + { + "code": "missing-contenteditable-attribute", + "message": "'contenteditable' attribute is required for textContent and innerHTML two-way bindings", + "start": { + "line": 6, + "column": 3, + "character": 157 + }, + "end": { + "line": 6, + "column": 24, + "character": 178 + }, + "pos": 157 + } +] diff --git a/test/validator/samples/a11y-contenteditable-element-without-child/input.svelte b/test/validator/samples/a11y-contenteditable-element-without-child/input.svelte new file mode 100644 index 000000000000..0702c3cb4578 --- /dev/null +++ b/test/validator/samples/a11y-contenteditable-element-without-child/input.svelte @@ -0,0 +1,6 @@ + +

+

+

From 6cd98c1bd52878c7b98b3cc7407c2237f7fedac5 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Tue, 23 Jun 2020 16:01:55 -0400 Subject: [PATCH 3/3] tidy --- src/compiler/compile/nodes/Element.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 8ca54b004b29..7a70e603a77f 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -708,8 +708,7 @@ export default class Element extends Node { if (!a11y_required_content.has(this.name)) return; if ( this.bindings - .map((binding) => binding.name) - .some((name) => ['textContent', 'innerHTML'].includes(name)) + .some((binding) => ['textContent', 'innerHTML'].includes(binding.name)) ) return; if (this.children.length === 0) {