Commit 6d5d9630 authored by David Sveningsson's avatar David Sveningsson

fix(rules): add `aria-label` helper

parent dd368f95
import { DynamicValue, HtmlElement } from "../../dom";
import { hasAriaLabel } from "./has-aria-label";
test("should return true if element has aria-label with text", () => {
const node = new HtmlElement("img");
node.setAttribute("aria-label", "foobar", null, null);
expect(hasAriaLabel(node)).toBeTruthy();
});
test("should return true if element has dynamic aria-label", () => {
const node = new HtmlElement("img");
node.setAttribute("aria-label", new DynamicValue("expr"), null, null);
expect(hasAriaLabel(node)).toBeTruthy();
});
test("should return false if element does not have aria-label", () => {
const node = new HtmlElement("img");
expect(hasAriaLabel(node)).toBeFalsy();
});
test("should return false if element has empty aria-label text", () => {
const node = new HtmlElement("img");
node.setAttribute("aria-label", "", null, null);
expect(hasAriaLabel(node)).toBeFalsy();
});
test("should return false if element has boolean aria-label attribute", () => {
const node = new HtmlElement("img");
node.setAttribute("aria-label", null, null, null);
expect(hasAriaLabel(node)).toBeFalsy();
});
import { HtmlElement } from "../../dom";
export function hasAriaLabel(node: HtmlElement): boolean {
const label = node.getAttribute("aria-label");
/* missing or boolean */
if (label === null || label.value === null) {
return false;
}
return label.isDynamic || label.value.toString() !== "";
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment