Commit 9c70db24 authored by David Sveningsson's avatar David Sveningsson

fix: validate `input[list]`

parent 474209ac
Pipeline #125447635 passed with stages
in 11 minutes and 1 second
......@@ -5,17 +5,18 @@ category: document
summary: Require all element references to exist
---
# no missing references (`no-missing-references`)
# No missing references (`no-missing-references`)
Require all elements referenced by attributes such as `for` to exist in the
current document.
Checked attributes:
- `for`
- `aria-controls`
- `aria-describedby`
- `aria-labelledby`
- `label[for]`
- `input[list]`
- `*[aria-controls]`
- `*[aria-describedby]`
- `*[aria-labelledby]`
## Rule details
......
......@@ -17,6 +17,13 @@ describe("rule no-missing-references", () => {
expect(report).toBeValid();
});
it('should not report error when <input list=".."> is referencing existing element', () => {
const report = htmlvalidate.validateString(
'<input list="existing"><datalist id="existing"></datalist>'
);
expect(report).toBeValid();
});
it('should not report error when <ANY aria-labelledby=".."> is referencing existing element', () => {
const report = htmlvalidate.validateString(
'<div aria-labelledby="existing"></div><span id="existing"></span>'
......@@ -57,6 +64,15 @@ describe("rule no-missing-references", () => {
);
});
it('should report error when <input list=".."> is referencing missing element', () => {
const report = htmlvalidate.validateString('<input list="missing">');
expect(report).toBeInvalid();
expect(report).toHaveError(
"no-missing-references",
'Element references missing id "missing"'
);
});
it('should report error when <ANY aria-labelledby=".."> is referencing missing element', () => {
const report = htmlvalidate.validateString(
'<div aria-labelledby="missing"></div>'
......
......@@ -34,6 +34,12 @@ class NoMissingReferences extends Rule<Context> {
this.validateReference(document, node, attr);
}
/* verify <input list=".."> */
for (const node of document.querySelectorAll("input[list]")) {
const attr = node.getAttribute("list");
this.validateReference(document, node, attr);
}
/* verify WAI-ARIA properties */
for (const property of ARIA) {
for (const node of document.querySelectorAll(`[${property}]`)) {
......
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