You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(utils): add support for complex CSS selectors (#1494)
Updates the CSS Selector Parser to allow more complex selectors: `:not`, `^=`, `$=`, and `*=`. Also update docs to describe what selectors we support.
Closes: #1493
## Reviewer checks
**Required fields, to be filled out by PR reviewer(s)**
- [x] Follows the commit message policy, appropriate for next version
- [x] Has documentation updated, a DU ticket, or requires no documentation change
- [x] Includes new tests, or was unnecessary
- [x] Code is reviewed for security by: @WilcoFiers
Copy file name to clipboardExpand all lines: doc/API.md
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,15 +176,15 @@ axe.configure({
176
176
- The rules attribute is an Array of rule objects
177
177
- each rule object can contain the following attributes
178
178
-`id` - string(required). This uniquely identifies the rule. If the rule already exists, it will be overridden with any of the attributes supplied. The attributes below that are marked required, are only required for new rules.
179
-
-`selector` - string(optional, default `*`). A CSS selector used to identify the elements that are passed into the rule for evaluation.
179
+
-`selector` - string(optional, default `*`). A [CSS selector](./developer-guide.md#supported-css-selectors) used to identify the elements that are passed into the rule for evaluation.
180
180
-`excludeHidden` - boolean(optional, default `true`). This indicates whether elements that are hidden from all users are to be passed into the rule for evaluation.
181
181
-`enabled` - boolean(optional, default `true`). Whether the rule is turned on. This is a common attribute for overriding.
182
182
-`pageLevel` - boolean(optional, default `false`). When set to true, this rule is only applied when the entire page is tested. Results from nodes on different frames are combined into a single result. See [page level rules](#page-level-rules).
183
183
-`any` - array(optional, default `[]`). This is a list of checks that, if none "pass", will generate a violation.
184
184
-`all` - array(optional, default `[]`). This is a list of checks that, if any "fails", will generate a violation.
185
185
-`none` - array(optional, default `[]`). This is a list of checks that, if any "pass", will generate a violation.
186
186
-`tags` - array(optional, default `[]`). A list if the tags that "classify" the rule. In practice, you must supply some valid tags or the default evaluation will not invoke the rule. The convention is to include the standard (WCAG 2 and/or section 508), the WCAG 2 level, Section 508 paragraph, and the WCAG 2 success criteria. Tags are constructed by converting all letters to lower case, removing spaces and periods and concatinating the result. E.g. WCAG 2 A success criteria 1.1.1 would become ["wcag2a", "wcag111"]
187
-
-`matches` - string(optional, default `*`). A filtering CSS selector that will exclude elements that do not match the CSS selector.
187
+
-`matches` - string(optional, default `*`). A filtering [CSS selector](./developer-guide.md#supported-css-selectors) that will exclude elements that do not match the CSS selector.
188
188
-`disableOtherRules` - Disables all rules not included in the `rules` property.
189
189
-`locale` - A locale object to apply (at runtime) to all rules and checks, in the same shape as `/locales/*.json`.
190
190
@@ -251,11 +251,7 @@ By default, `axe.run` will test the entire document. The context object is an op
251
251
- Example: To limit analysis to the `<div id="content">` element: `document.getElementById("content")`
252
252
253
253
2. A NodeList such as returned by `document.querySelectorAll`.
254
-
3. A CSS selector that selects the portion(s) of the document that must be analyzed. This includes:
255
-
256
-
- A CSS selector as a class name (e.g. `.classname`)
257
-
- A CSS selector as a node name (e.g. `div`)
258
-
- A CSS selector of an element id (e.g. `#tag`)
254
+
3. A [CSS selector](./developer-guide.md#supported-css-selectors) that selects the portion(s) of the document that must be analyzed.
259
255
260
256
4. An include-exclude object (see below)
261
257
@@ -264,7 +260,7 @@ By default, `axe.run` will test the entire document. The context object is an op
264
260
The include exclude object is a JSON object with two attributes: include and exclude. Either include or exclude is required. If only `exclude` is specified; include will default to the entire `document`.
265
261
266
262
- A node, or
267
-
- An array of arrays of CSS selectors
263
+
- An array of arrays of [CSS selectors](./developer-guide.md#supported-css-selectors)
268
264
- If the nested array contains a single string, that string is the CSS selector
-`virtualNode` – object, the flattened DOM tree to query against. `axe._tree` is available for this purpose during an audit; see below.
706
-
-`selector` – string, the CSS selector to use as a filter. For the most part, this should work seamlessly with `document.querySelectorAll`.
702
+
-`selector` – string, the [CSS selector](./developer-guide.md#supported-css-selectors) to use as a filter. For the most part, this should work seamlessly with `document.querySelectorAll`.
Copy file name to clipboardExpand all lines: doc/developer-guide.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,11 @@ Axe runs a series of tests to check for accessibility of content and functionali
5
5
Axe 3.0 supports open Shadow DOM: see our virtual DOM APIs and test utilities for developing axe-core moving forward. Note: we do not and cannot support closed Shadow DOM.
Axe tests for accessibility using objects called Rules. Each Rule tests for a high-level aspect of accessibility, such as color contrast, button labels, and alternate text for images. Each rule is made up of a series of Checks. Depending on the rule; all, some, or none of these checks must pass in order for the rule to pass.
@@ -62,7 +76,7 @@ After execution, a Check will return `true` or `false` depending on whether or n
62
76
Rules are defined by JSON files in the [lib/rules directory](../lib/rules). The JSON object is used to seed the [Rule object](../lib/core/base/rule.js#L30). A valid Rule JSON consists of the following:
63
77
64
78
-`id` - `String` A unique name of the Rule.
65
-
-`selector` - **optional**`String` which is a CSS selector that specifies the elements of the page on which the Rule runs. axe-core will look inside of the light DOM and _open_[Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM) trees for elements matching the provided selector. If omitted, the rule will run against every node.
79
+
-`selector` - **optional**`String` which is a [CSS selector](#supported-css-selectors) that specifies the elements of the page on which the Rule runs. axe-core will look inside of the light DOM and _open_[Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM) trees for elements matching the provided selector. If omitted, the rule will run against every node.
66
80
-`excludeHidden` - **optional**`Boolean` Whether the rule should exclude hidden elements. Defaults to `true`.
67
81
-`enabled` - **optional**`Boolean` Whether the rule is enabled by default. Defaults to `true`.
68
82
-`pageLevel` - **optional**`Boolean` Whether the rule is page level. Page level rules will only run if given an entire `document` as context.
0 commit comments