fix: make active + ancestor links accessible (#1915)

This commit is contained in:
Marvin Hagemeister
2023-10-11 17:29:07 +02:00
committed by GitHub
parent 77bc15cb6f
commit 78b0b05fc3
3 changed files with 29 additions and 0 deletions
+24
View File
@@ -976,15 +976,21 @@ Deno.test("active links without client nav", async () => {
// Current
assertNotSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, "a[href='/active_nav'][data-current]");
assertSelector(doc, `a[href='/active_nav'][aria-current="page"]`);
// Unrelated links
assertNotSelector(doc, "a[href='/active_nav/foo'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo'][aria-current]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][aria-current]");
doc = await server.getHtml(`/active_nav/foo`);
assertSelector(doc, "a[href='/active_nav/foo'][data-current]");
assertSelector(doc, `a[href='/active_nav/foo'][aria-current="page"]`);
assertSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, `a[href='/active_nav'][aria-current="true"]`);
assertSelector(doc, "a[href='/'][data-ancestor]");
assertSelector(doc, `a[href='/'][aria-current="true"]`);
},
);
});
@@ -1001,22 +1007,40 @@ Deno.test("Updates active links outside of vdom", async () => {
// Current
assertNotSelector(doc, "a[href='/active_nav_partial'][data-ancestor]");
assertSelector(doc, "a[href='/active_nav_partial'][data-current]");
assertSelector(doc, `a[href='/active_nav_partial'][aria-current="page"]`);
// Unrelated links
assertNotSelector(
doc,
"a[href='/active_nav_partial/foo'][data-ancestor]",
);
assertNotSelector(
doc,
"a[href='/active_nav_partial/foo'][aria-current]",
);
assertNotSelector(
doc,
"a[href='/active_nav_partial/foo/bar'][data-ancestor]",
);
assertNotSelector(
doc,
"a[href='/active_nav_partial/foo/bar'][aria-current]",
);
await page.goto(`${address}/active_nav_partial/foo`);
doc = parseHtml(await page.content());
assertSelector(doc, "a[href='/active_nav_partial/foo'][data-current]");
assertSelector(
doc,
`a[href='/active_nav_partial/foo'][aria-current="page"]`,
);
assertSelector(doc, "a[href='/active_nav_partial'][data-ancestor]");
assertSelector(
doc,
`a[href='/active_nav_partial'][data-ancestor][aria-current="true"]`,
);
assertSelector(doc, "a[href='/'][data-ancestor]");
assertSelector(doc, `a[href='/'][aria-current="true"]`);
},
);
});