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

Shadow DOM docs #471

Merged
merged 15 commits into from
Aug 8, 2017
Merged

Shadow DOM docs #471

merged 15 commits into from
Aug 8, 2017

Conversation

marcysutton
Copy link
Contributor

Should close #401. Feedback welcome!

@marcysutton marcysutton changed the title Shadow docs Shadow DOM docs Aug 3, 2017
Copy link
Contributor

@WilcoFiers WilcoFiers left a 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.
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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:
Copy link
Contributor

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"?

```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);
Copy link
Contributor

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.

}
```

`virtualAccessibleText` would never be called directly; rather, it would be called
Copy link
Contributor

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.

Copy link
Contributor Author

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?

@WilcoFiers
Copy link
Contributor

WilcoFiers commented Aug 4, 2017 via email

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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).

@@ -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.
Copy link
Contributor

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`.
Copy link
Contributor

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?

Copy link
Contributor Author

@marcysutton marcysutton Aug 4, 2017

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

Copy link
Contributor Author

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.

```

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
Copy link
Contributor

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
Copy link
Contributor

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)

@marcysutton
Copy link
Contributor Author

marcysutton commented Aug 4, 2017

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.

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.

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@WilcoFiers WilcoFiers left a 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?

@marcysutton
Copy link
Contributor Author

That's fine by me, I'll move the test utilities over there too. Thanks!

@marcysutton
Copy link
Contributor Author

Ok, I moved them to the developer guide and added a table of contents to it.

@marcysutton marcysutton merged commit 57ccbbd into shadowDOM Aug 8, 2017
@marcysutton marcysutton deleted the shadow-docs branch August 8, 2017 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants