Commit 244d37d3 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(dom): `input[type="hidden"]` no longer labelable

parent bda8a9f6
......@@ -533,7 +533,7 @@
"phrasing": true,
"interactive": ["matchAttribute", ["type", "!=", "hidden"]],
"void": true,
"labelable": true,
"labelable": ["matchAttribute", ["type", "!=", "hidden"]],
"deprecatedAttributes": [
"datasrc",
"datafld",
......
import { Source } from "../src/context";
import { HtmlElement } from "../src/dom";
import HtmlValidate from "../src/htmlvalidate";
import "../src/matchers";
......@@ -178,6 +180,37 @@ describe("HTML elements", () => {
},
});
function getElement(markup: string, selector: string): HtmlElement {
const source: Source = {
data: markup,
filename: "inline",
line: 1,
column: 1,
offset: 0,
};
const parser = htmlvalidate.getParserFor(source);
const doc = parser.parseHtml(source.data);
return doc.querySelector(selector);
}
describe("<input>", () => {
it("should be labelable unless hidden", () => {
expect.assertions(1);
const markup = '<input type="text">';
const input = getElement(markup, "input");
const meta = input.meta;
expect(meta?.labelable).toBeTruthy();
});
it("should not be labelable if hidden", () => {
expect.assertions(1);
const markup = '<input type="hidden">';
const input = getElement(markup, "input");
const meta = input.meta;
expect(meta?.labelable).toBeFalsy();
});
});
describe(`global attributes`, () => {
it("valid markup", () => {
expect.assertions(1);
......
......@@ -55,7 +55,7 @@ export interface MetaData {
implicitClosed?: string[];
scriptSupporting?: boolean;
form?: boolean;
labelable?: boolean;
labelable?: boolean | PropertyExpression;
/* attribute */
deprecatedAttributes?: string[];
......
......@@ -23,6 +23,7 @@ const dynamicKeys = [
"phrasing",
"embedded",
"interactive",
"labelable",
];
type PropertyEvaluator = (node: HtmlElement, options: any) => boolean;
......
Supports Markdown
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