-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-scan
- Loading branch information
Showing
6 changed files
with
113 additions
and
32 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-selector": minor | ||
--- | ||
|
||
**Added:** The `:checked` pseudo-class is now supported. |
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
48 changes: 48 additions & 0 deletions
48
packages/alfa-selector/src/selector/simple/pseudo-class/checked.ts
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,48 @@ | ||
import { Element } from "@siteimprove/alfa-dom"; | ||
import { Predicate } from "@siteimprove/alfa-predicate"; | ||
|
||
import { PseudoClassSelector } from "./pseudo-class.js"; | ||
|
||
const { hasAttribute, hasInputType, hasName } = Element; | ||
const { and, or } = Predicate; | ||
|
||
/** | ||
* {@link https://drafts.csswg.org/selectors/#checked} | ||
*/ | ||
export class Checked extends PseudoClassSelector<"checked"> { | ||
public static of(): Checked { | ||
return new Checked(); | ||
} | ||
|
||
private constructor() { | ||
super("checked"); | ||
} | ||
|
||
public *[Symbol.iterator](): Iterator<Checked> { | ||
yield this; | ||
} | ||
|
||
/** | ||
* @privateRemarks | ||
* Checkedness and selectedness can change during the lifecycle of an element, | ||
* but we do not have access to that. We rely on the content attributes being | ||
* correctly set in the snapshot we test. | ||
*/ | ||
public matches = or( | ||
and(hasInputType("checkbox", "radio"), hasAttribute("checked")), | ||
and(hasName("option"), hasAttribute("selected")), | ||
); | ||
|
||
public toJSON(): Checked.JSON { | ||
return super.toJSON(); | ||
} | ||
} | ||
|
||
export namespace Checked { | ||
export interface JSON extends PseudoClassSelector.JSON<"checked"> {} | ||
|
||
export const parse = PseudoClassSelector.parseNonFunctional( | ||
"checked", | ||
Checked.of, | ||
); | ||
} |
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