-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIA-R8: add type="password" (and more) to applicability (#1667)
* adding failing unit test. * adding more fialing tests. * adding type="password" fields to the applicability. seems to work i.e. make the tests pass. * adding expecations Outcomes specifically for the input type="password" case. * - expanded applicability to include many more type="" attribute values. inspired act-rules/act-rules.github.io#2123 (comment) - added corresponding unit tests. they pass. * changeset. * changeset. * Update packages/alfa-rules/src/sia-r8/rule.ts Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * fixing recently-introduced compilation error, I think. * fixing recently-introduced error in test. * changing import style as per review advice at #1667 (comment) * tightening up the types by using the same InputType type that hasInputType uses (instead of string). as per review comment at #1667 (comment) * removing unused import. * Update packages/alfa-rules/test/sia-r8/rule.spec.tsx Co-authored-by: Jean-Yves Moyen <[email protected]> * making new experimental rule: sia-er8. (as per review comment at #1667 (review) ) so this commit effectively reverts sia-r8. * changeset. * refactoring as per review comment at #1667 (comment) * Extract API * Update .changeset/swift-meals-check.md Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/src/experimental.ts Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/src/sia-er8/rule.ts Co-authored-by: Jean-Yves Moyen <[email protected]> * Update packages/alfa-rules/src/sia-er8/rule.ts Co-authored-by: Jean-Yves Moyen <[email protected]> * minor fixes - consequent to the review at #1667 (review) * Extract API --------- Co-authored-by: Jean-Yves Moyen <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ff43035
commit 15fabab
Showing
9 changed files
with
485 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@siteimprove/alfa-rules": minor | ||
--- | ||
|
||
**Added:** Experimental rule SIA-ER8. It adds support for type="password" and more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import ER8 from "./sia-er8/rule.js"; | ||
import ER87 from "./sia-er87/rule.js"; | ||
|
||
import R82 from "./sia-r82/rule.js"; | ||
import R109 from "./sia-r109/rule.js"; | ||
|
||
export { ER87, R82, R109 }; | ||
export { ER8, ER87, R82, R109 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Diagnostic, Rule } from "@siteimprove/alfa-act"; | ||
import type { Role } from "@siteimprove/alfa-aria"; | ||
import * as aria from "@siteimprove/alfa-aria" | ||
import { Element, Namespace, Node, Query } from "@siteimprove/alfa-dom"; | ||
import { Predicate } from "@siteimprove/alfa-predicate"; | ||
import { Err, Ok } from "@siteimprove/alfa-result"; | ||
import { Criterion } from "@siteimprove/alfa-wcag"; | ||
import type { Page } from "@siteimprove/alfa-web"; | ||
|
||
import { expectation } from "../common/act/expectation.js"; | ||
|
||
import { Scope, Stability, Version } from "../tags/index.js"; | ||
import { WithRole } from "../common/diagnostic.js"; | ||
|
||
const { hasNonEmptyAccessibleName, hasRole, isIncludedInTheAccessibilityTree } = aria.DOM; | ||
const { hasInputType, hasNamespace } = Element; | ||
const { and, or } = Predicate; | ||
const { getElementDescendants } = Query; | ||
|
||
export default Rule.Atomic.of<Page, Element>({ | ||
uri: "https://alfa.siteimprove.com/rules/sia-r8", | ||
requirements: [Criterion.of("4.1.2")], | ||
tags: [Scope.Component, Stability.Experimental, Version.of(2)], | ||
evaluate({ device, document }) { | ||
return { | ||
applicability() { | ||
return getElementDescendants(document, Node.fullTree).filter( | ||
and( | ||
hasNamespace(Namespace.HTML), | ||
or( | ||
hasRole( | ||
device, | ||
"checkbox", | ||
"combobox", | ||
"listbox", | ||
"menuitemcheckbox", | ||
"menuitemradio", | ||
"radio", | ||
"searchbox", | ||
"slider", | ||
"spinbutton", | ||
"switch", | ||
"textbox", | ||
), | ||
hasInputType("password", "color", "date", "datetime-local", "file", "month", "time", "week"), | ||
), | ||
isIncludedInTheAccessibilityTree(device), | ||
), | ||
); | ||
}, | ||
|
||
expectations(target) { | ||
const role = aria.Node.from(target, device).role; | ||
if(role.isSome()) { | ||
const roleName = role.get().name; | ||
return { | ||
1: expectation( | ||
hasNonEmptyAccessibleName(device)(target), | ||
() => Outcomes.FormFieldWithAriaRoleHasName(roleName), | ||
() => Outcomes.FormFieldWithAriaRoleHasNoName(roleName), | ||
), | ||
}; | ||
} else { | ||
// We know the type attribute has a correct value because of the applicability. | ||
const inputType = target.attribute("type").map(attr => attr.value).getUnsafe(`R8v2 found an element with no role nor 'type' attribute: ${target.path()}`) as Element.InputType; | ||
return { | ||
1: expectation( | ||
hasNonEmptyAccessibleName(device)(target), | ||
() => Outcomes.InputElementWithNoAriaRoleHasName(inputType), | ||
() => Outcomes.InputElementWithNoAriaRoleHasNoName(inputType), | ||
), | ||
}; | ||
} | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
/** | ||
* @public | ||
*/ | ||
export namespace Outcomes { | ||
export const FormFieldWithAriaRoleHasName = (role: Role.Name) => | ||
Ok.of(WithRole.of(`The form field has an accessible name`, role)); | ||
|
||
export const FormFieldWithAriaRoleHasNoName = (role: Role.Name) => | ||
Err.of( | ||
WithRole.of(`The form field does not have an accessible name`, role), | ||
); | ||
|
||
export const InputElementWithNoAriaRoleHasName = (typeAttribValue: Element.InputType) => | ||
Ok.of(Diagnostic.of(`The type="${typeAttribValue}" form field has an accessible name`)); | ||
|
||
export const InputElementWithNoAriaRoleHasNoName = (typeAttribValue: Element.InputType) => | ||
Err.of(Diagnostic.of(`The type="${typeAttribValue}" form field does not have an accessible name`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.