Skip to content

Commit

Permalink
implement bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Jun 26, 2024
1 parent 88b19df commit f72b38b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/rules/bypass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AccessibilityError } from "../scanner";
import { querySelector, querySelectorAll } from "../utils";

const id = "ye5d6e";
const url = `https://act-rules.github.io/rules/${id}`;
const text = "Document has an instrument to move focus to non-repeated content";

// TODO: The tests don't work yet because the document doesn't load correctly in the test harness.
export default function (el: Document | Element): AccessibilityError[] {
const errors = [];
const document = el instanceof Document ? el : el.ownerDocument;
const links = querySelectorAll("a[href^='#']", document);

let hasInstrument = false;

for (const link of links) {
const target = querySelector(link.getAttribute("href")!, document);
if (target?.parentElement?.isSameNode(document.body)) hasInstrument = true;
}
if (hasInstrument) {
errors.push({
element: document.body,
text,
url,
});
}
return errors;
}
2 changes: 2 additions & 0 deletions src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import label from "./rules/label";
import linkName from "./rules/link-name";
import nestedInteractive from "./rules/nested-interactive";
import validLang from "./rules/valid-lang";
import bypass from "./rules/bypass";

import { Logger } from "./logger";

Expand Down Expand Up @@ -38,6 +39,7 @@ export const allRules: Rule[] = [
linkName,
nestedInteractive,
validLang,
bypass,
];

export async function requestIdleScan(
Expand Down

0 comments on commit f72b38b

Please sign in to comment.