Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align R18 with specification #1541

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-coats-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-rules": minor
rcj-siteimprove marked this conversation as resolved.
Show resolved Hide resolved
---

**Fixed:** SIA-R18 now accepts attributes for `input type=file` and `input type=color` according to the [ARIA in HTML](https://w3c.github.io/html-aria/#el-input-file) specification
1 change: 1 addition & 0 deletions packages/alfa-aria/src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ const Features: Features = {
return element.attribute("list").isSome()
? "combobox"
: "searchbox";
// Note: The specification for email has changed, it now has role textbox. We should look into this if it becomes an issue.
case "email":
case "tel":
case "text":
Expand Down
39 changes: 28 additions & 11 deletions packages/alfa-rules/src/sia-r18/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ export default Rule.Atomic.of<Page, Attribute>({
},
});

function allowedForInputType(
attributeName: aria.Attribute.Name,
): Predicate<Element> {
return hasInputType((inputType) => {
switch (inputType) {
case "color":
return attributeName === "aria-disabled";
case "date":
case "datetime-local":
case "email":
case "month":
case "password":
case "time":
case "week":
return Role.of("textbox").isAttributeSupported(attributeName);
case "file":
return (
attributeName === "aria-disabled" ||
attributeName === "aria-invalid" ||
attributeName === "aria-required"
);
default:
return false;
}
});
}

function ariaHtmlAllowed(target: Attribute): boolean {
const attributeName = target.name as aria.Attribute.Name;
for (const element of target.owner) {
Expand All @@ -78,17 +105,7 @@ function ariaHtmlAllowed(target: Attribute): boolean {
return Role.of("document").isAttributeSupported(attributeName);

case "input":
return (
hasInputType(
"date",
"datetime-local",
"email",
"month",
"password",
"time",
"week",
)(element) && Role.of("textbox").isAttributeSupported(attributeName)
);
return allowedForInputType(attributeName)(element);

case "select":
return (
Expand Down
52 changes: 52 additions & 0 deletions packages/alfa-rules/test/sia-r18/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,58 @@ test(`evaluate() passes input with type password field and aria-required state`,
]);
});

test(`evaluate() passes input with type file field and aria-disabled state`, async (t) => {
const target = <input type="file" aria-disabled="true" />;

const document = h.document([target]);

t.deepEqual(await evaluate(R18, { document }), [
passed(R18, target.attribute("aria-disabled").getUnsafe(), {
1: Outcomes.IsAllowed,
2: Outcomes.IsNotProhibited,
}),
]);
});

test(`evaluate() passes input with type file field and aria-invalid state`, async (t) => {
const target = <input type="file" aria-invalid="true" />;

const document = h.document([target]);

t.deepEqual(await evaluate(R18, { document }), [
passed(R18, target.attribute("aria-invalid").getUnsafe(), {
1: Outcomes.IsAllowed,
2: Outcomes.IsNotProhibited,
}),
]);
});

test(`evaluate() passes input with type file field and aria-required state`, async (t) => {
const target = <input type="file" aria-required="true" />;

const document = h.document([target]);

t.deepEqual(await evaluate(R18, { document }), [
passed(R18, target.attribute("aria-required").getUnsafe(), {
1: Outcomes.IsAllowed,
2: Outcomes.IsNotProhibited,
}),
]);
});

test(`evaluate() passes input with type color field and aria-disabled state`, async (t) => {
const target = <input type="color" aria-disabled="true" />;

const document = h.document([target]);

t.deepEqual(await evaluate(R18, { document }), [
passed(R18, target.attribute("aria-disabled").getUnsafe(), {
1: Outcomes.IsAllowed,
2: Outcomes.IsNotProhibited,
}),
]);
});

test(`evaluate() passes a button with aria-pressed state`, async (t) => {
const target = <button aria-pressed="false">My button</button>;

Expand Down