From 4ba3c613f2ed4bcd493cbc44794e77cc45392360 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Tue, 8 Aug 2023 14:21:39 +0200 Subject: [PATCH 1/5] Add breaking test --- packages/alfa-rules/test/sia-r19/rule.spec.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/alfa-rules/test/sia-r19/rule.spec.tsx b/packages/alfa-rules/test/sia-r19/rule.spec.tsx index d8c81c0549..ea1919492b 100644 --- a/packages/alfa-rules/test/sia-r19/rule.spec.tsx +++ b/packages/alfa-rules/test/sia-r19/rule.spec.tsx @@ -291,6 +291,19 @@ test("evaluate() fails a required aria-controls property pointing to a non-exist ]); }); +test("evaluate() passes a required aria-controls property pointing to an existent ID", async (t) => { + const target =
; + const controlled =
; + + const document = h.document([target, controlled]); + + t.deepEqual(await evaluate(R19, { document }), [ + passed(R19, target.attribute("aria-controls").getUnsafe(), { + 1: Outcomes.HasValidValue, + }), + ]); +}); + test("evaluate() is inapplicable when an element does not have any ARIA attribute", async (t) => { const document = h.document([
Some Content
]); From b5dc6cfac70ef672308ec7a5d2f74d10e2634ef1 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Tue, 8 Aug 2023 14:27:56 +0200 Subject: [PATCH 2/5] Improve documentation --- packages/alfa-dom/src/node/query/element-id-map.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/alfa-dom/src/node/query/element-id-map.ts b/packages/alfa-dom/src/node/query/element-id-map.ts index b0b956aaf1..903c79e043 100644 --- a/packages/alfa-dom/src/node/query/element-id-map.ts +++ b/packages/alfa-dom/src/node/query/element-id-map.ts @@ -10,10 +10,13 @@ import { getElementDescendants } from "./element-descendants"; const elementMapCache = Cache.empty>(); /** - * @public + * Returns a map from id to elements, in the subtree rooted at a given node. * - * @remarks Since `id` are scoped to trees, and do not cross shadow or content boundaries, + * @privateRemarks + * Since `id` are scoped to trees, and do not cross shadow or content boundaries, * we never need traversal options. + * + * @public */ export function getElementIdMap(node: Node): Map { if (Document.isDocument(node)) { From 2abb2bace7de5d6250b271106111ca686db63456 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Tue, 8 Aug 2023 14:28:24 +0200 Subject: [PATCH 3/5] Correctly search for id in the full tree --- packages/alfa-rules/src/sia-r19/rule.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/alfa-rules/src/sia-r19/rule.ts b/packages/alfa-rules/src/sia-r19/rule.ts index 6d8a7edd4d..ebf1036930 100644 --- a/packages/alfa-rules/src/sia-r19/rule.ts +++ b/packages/alfa-rules/src/sia-r19/rule.ts @@ -115,7 +115,8 @@ function isValid(attribute: aria.Attribute): boolean { } function treeHasId(id: string, node: Node): boolean { - return Query.getElementIdMap(node).has(id); + // Since ID are scoped to tree, we need no traversal option to find the root. + return Query.getElementIdMap(node.root()).has(id); } /** From fcf8156d76cee7abe96e4d0d17ccde83a00308c4 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Tue, 8 Aug 2023 14:29:00 +0200 Subject: [PATCH 4/5] Update documentation --- docs/review/api/alfa-dom.api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/review/api/alfa-dom.api.md b/docs/review/api/alfa-dom.api.md index ce19bb2200..3ea372db58 100644 --- a/docs/review/api/alfa-dom.api.md +++ b/docs/review/api/alfa-dom.api.md @@ -409,7 +409,7 @@ export namespace Fragment { // @public (undocumented) function getElementDescendants(node: Node, options?: Node.Traversal): Sequence; -// @public (undocumented) +// @public function getElementIdMap(node: Node): Map_2; // Warning: (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts From dc5088223d03274e90be29845ef797e8bc32d209 Mon Sep 17 00:00:00 2001 From: Jean-Yves Moyen Date: Tue, 8 Aug 2023 14:32:07 +0200 Subject: [PATCH 5/5] Add changeset --- .changeset/rotten-socks-approve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rotten-socks-approve.md diff --git a/.changeset/rotten-socks-approve.md b/.changeset/rotten-socks-approve.md new file mode 100644 index 0000000000..50e90b4a05 --- /dev/null +++ b/.changeset/rotten-socks-approve.md @@ -0,0 +1,5 @@ +--- +"@siteimprove/alfa-rules": patch +--- + +**Fixed:** SIA-R19 correctly searches for `id` in the full DOM tree again (instead of the subtree of the element).