Commit 41c39e91 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(rules): `input-missing-label` ignores hidden `<input>`

parent ae20335f
......@@ -28,6 +28,18 @@ describe("rule input-missing-label", () => {
expect(report).toBeValid();
});
it("should not report when input is hidden", () => {
expect.assertions(1);
const report = htmlvalidate.validateString("<input hidden>");
expect(report).toBeValid();
});
it("should not report when input is aria-hidden", () => {
expect.assertions(1);
const report = htmlvalidate.validateString('<input aria-hidden="true">');
expect(report).toBeValid();
});
it.each(["input", "textarea", "select"])(
"should report when <%s> is missing label",
(tagName: string) => {
......
import { DOMTree, HtmlElement } from "../dom";
import { DOMReadyEvent } from "../event";
import { Rule, RuleDocumentation, ruleDocumentationUrl } from "../rule";
import { isAriaHidden, isHTMLHidden } from "./helper/a17y";
export default class InputMissingLabel extends Rule {
public documentation(): RuleDocumentation {
......@@ -14,6 +15,10 @@ export default class InputMissingLabel extends Rule {
this.on("dom:ready", (event: DOMReadyEvent) => {
const root = event.document;
for (const elem of root.querySelectorAll("input, textarea, select")) {
if (isHTMLHidden(elem) || isAriaHidden(elem)) {
continue;
}
/* <input type="hidden"> should not have label */
if (elem.is("input")) {
const type = elem.getAttributeValue("type");
......
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