-
Notifications
You must be signed in to change notification settings - Fork 779
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
Shadow DOM docs #471
Shadow DOM docs #471
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few more methods I think we should add. The test utilities are important, as well as dom.getComposedParent
, dom.getRootNode
and maybe also dom.findUp
.
doc/API.md
Outdated
|
||
##### Description | ||
|
||
Recursvely return an array containing the virtual DOM tree for the node specified, excluding comment nodes and shadow DOM nodes `<content> and `<slot>`. This method will return a composed tree containing both light and shadow DOM, if applicable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use HTML entities here. Anything in backticks is escaped automatically (have a look at how Github rendered this line). Also, you're missing a backtick char.
doc/API.md
Outdated
@@ -608,6 +613,120 @@ In axe-core v1 the main method for axe was `axe.a11yCheck()`. This method was re | |||
- .a11yCheck requires a context object, and so will not fall back to the document root. | |||
- .a11yCheck does not return a Promise. | |||
|
|||
### Virtual DOM Utilities | |||
|
|||
#### API Name: axe.utils.getFlattenedTree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to document this method? People shouldn't use this in their checks. The only place this is relevant is in testing, and for those scenarios we have test utilities that do this stuff for them instead. Should we document testUtils instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add a method to set and clear the axe._tree cache then we would not need to document this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, if we do, then we should point ot the algorithm definition in the HTML spec (see the source code comments for the link)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need something to pass to axe.utils.getNodeFromTree
, so I'd vote for documenting it and dropping axe._tree
. But we could also do as Dylan suggests and create a method to set and clear the cache. I had some questions about that in a separate comment.
doc/API.md
Outdated
|
||
##### Returns | ||
|
||
An object containing the virtualNode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "A virtualNode object"?
doc/developer-guide.md
Outdated
```javascript | ||
axe.commons.text.accessibleText = function (element, inLabelledbyContext) { | ||
let virtualNode = axe.utils.getNodeFromTree(axe._tree[0]); // throws an exception on purpose if axe._tree not correct | ||
return axe.commons.text.virtualAccessibleText(virtualNode, inLabelledbyContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be text.accessibleTextVirtual
, although I just realized I messed up and didn't rename that one. I made a ticket for it.
doc/developer-guide.md
Outdated
} | ||
``` | ||
|
||
`virtualAccessibleText` would never be called directly; rather, it would be called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not true. We always call the virtual functions if we've got a virtual node we can use. Only if we don't have one do we use the lookup function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that make our rules/checks less backwards-compatible?
Nah, new rules should use them when they can, as that's more performant. We
have the old ones mostly to stay backward competable.
…On 4 Aug 2017 18:13, "Marcy Sutton" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In doc/developer-guide.md
<#471 (comment)>:
> +it expects to operate on a virtual DOM tree.
+
+Let’s look at an example:
+
+```javascript
+axe.commons.text.accessibleText = function (element, inLabelledbyContext) {
+ let virtualNode = axe.utils.getNodeFromTree(axe._tree[0]); // throws an exception on purpose if axe._tree not correct
+ return axe.commons.text.virtualAccessibleText(virtualNode, inLabelledbyContext);
+}
+
+axe.commons.text.virtualAccessibleText = function (element, inLabelledbyContext) {
+ // rest of the commons code minus the virtual tree lookup, since it’s passed in
+}
+```
+
+`virtualAccessibleText` would never be called directly; rather, it would be called
Wouldn't that make our rules/checks less backwards-compatible?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#471 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAgY_yjlhcJaTrpUyMCDyn8Vg9H6CAWQks5sU0NBgaJpZM4Os7jw>
.
|
doc/API.md
Outdated
1. [API Name: axe.utils.getFlattenedTree](#api-name-axeutilsgetflattenedtree) | ||
2. [API Name: axe.utils.getNodeFromTree](#api-name-axeutilsgetnodefromtree) | ||
3. [API Name: axe.utils.querySelectorAll](#api-name-axeutilsqueryselectorall) | ||
4. [API Name: axe._tree](#api-name-axe_tree) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a method to set and clear this from the outside rather than documenting the internal object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might just remove it for now so we don't hold up the release. Because I have questions about how that would work, since it gets set internally during the audit: 1. when would you set or clear it? 2. what should happen if you try to manipulate it at the wrong time?
doc/API.md
Outdated
@@ -608,6 +613,120 @@ In axe-core v1 the main method for axe was `axe.a11yCheck()`. This method was re | |||
- .a11yCheck requires a context object, and so will not fall back to the document root. | |||
- .a11yCheck does not return a Promise. | |||
|
|||
### Virtual DOM Utilities | |||
|
|||
#### API Name: axe.utils.getFlattenedTree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add a method to set and clear the axe._tree cache then we would not need to document this.
doc/API.md
Outdated
|
||
##### Parameters | ||
- `node` – node. The current HTML node for which you want a flattened DOM tree. | ||
- `shadowId` – string(optional). ID of the shadow DOM that is the closest shadow ancestor of the node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A caller should always call this with the shadowID undefined
as this parameter is intended only to be used by the recursive calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite following. Can't we set it as undefined
if it doesn't get passed in? This may also be moot if we drop documentation of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbd - I was just suggesting adding a note to say that it is not intended to be directly used by an external caller
doc/API.md
Outdated
|
||
##### Description | ||
|
||
A querySelectorAll implementation that works on the virtual DOM and Shadow DOM by manually walking the tree instead of relying on DOM API methods which don't step into Shadow DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It walks the flattened tree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It walks the flattened tree
Do you mean your implementation? Or document.querySelectorAll
? I assume you meant the former, but I wanted to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this implementation walks the flattened tree. It is like document|Element.querySelectorAll
except for the flattened tree rather than the DOM (light DOM).
doc/developer-guide.md
Outdated
@@ -41,7 +41,7 @@ After execution, a Check will return `true` or `false` depending on whether or n | |||
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: | |||
|
|||
* `id` - `String` A unique name of the Rule. | |||
* `selector` - **optional** `String` which is a CSS selector that specifies the elements of the page on which the Rule runs. If omitted, the rule will run against every node. | |||
* `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 *open* [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM) subtrees for elements matching the provided selector. If omitted, the rule will run against every node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should say the light DOM and and open shadow DOM trees
|
||
Occasionally, you may want to add additional information about why a Check passed or failed into its message. For example, the [aria-valid-attr](../lib/checks/aria/valid-attr.json) will add information about any invalid ARIA attributes to its fail message. The message uses the [doT.js](http://olado.github.io/doT/) and is compiled to a JavaScript function at build-time. In the Check message, you have access to the `CheckResult` as `it`. | ||
Occasionally, you may want to add additional information about why a Check passed, failed or returned undefined into its message. For example, the [aria-valid-attr](../lib/checks/aria/valid-attr.json) will add information about any invalid ARIA attributes to its fail message. The message uses the [doT.js](http://olado.github.io/doT/) and is compiled to a JavaScript function at build-time. In the Check message, you have access to the `CheckResult` as `it`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it could benefit from an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one, at least for incomplete messages, in my other PR. I could always expand on that later. #469
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an example in #469.
doc/developer-guide.md
Outdated
``` | ||
|
||
A virtualNode is an object containing an HTML DOM element (`actualNode`), an | ||
array of child virtualNodes, and, if provided when querying the virtual tree, a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shadowID indicates whether the node is in a shadow root and if it is, which one it is inside.
doc/API.md
Outdated
@@ -608,6 +613,120 @@ In axe-core v1 the main method for axe was `axe.a11yCheck()`. This method was re | |||
- .a11yCheck requires a context object, and so will not fall back to the document root. | |||
- .a11yCheck does not return a Promise. | |||
|
|||
### Virtual DOM Utilities | |||
|
|||
#### API Name: axe.utils.getFlattenedTree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, if we do, then we should point ot the algorithm definition in the HTML spec (see the source code comments for the link)
I didn't add those because they are commons functions and not utils, but it sounds like we had a request for documenting the rest of the commons. I won't go through all of those right now, but I can start with these few and the testUtils. |
9e17f8e
to
278a6c6
Compare
doc/API.md
Outdated
|
||
##### Description | ||
|
||
Recursvely return an array containing the virtual DOM tree for the node specified, excluding comment nodes and shadow DOM nodes `<content>` and `<slot>`. This method will return a composed tree containing both light and shadow DOM, if applicable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
composed tree
is an outdated term. The new term is flattened tree
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about axe.commons.dom.getComposedParent
? Is that still good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really excellent. Thank you Marcy! The one thing I still think needs to change is that the Virtual DOM Utilities in my opinion should be in developer-guide.md instead of in API.md. I think API.md should only contain code you need to run axe-core. The develop guide is more suited for stuff you only need to know if you start writing code for axe-core. WDYT?
That's fine by me, I'll move the test utilities over there too. Thanks! |
Ok, I moved them to the developer guide and added a table of contents to it. |
Should close #401. Feedback welcome!