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 support for color contrast matches #413

Merged
merged 9 commits into from
Jul 13, 2017

Conversation

marcysutton
Copy link
Contributor

This PR builds on #404 to pull in some of the commons already in use.

Closes #393.

Copy link
Contributor

@dylanb dylanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcysutton There are a bunch of changes that need to be made in lib/rules/color-contrast-matches.js to get it to support shadow DOM correctly.

  1. When finding the appropriate document object to use for idref lookups, you need to use axe.commons.dom.getRootNode(node). So for example before line 43, you need to call getRootNode to get the document for the relevantNode so the idref dereferences correctly.
  2. On line 50, where the code is looking for a wrapped input element, we need to use the axe.utils.querySelectorAll() function on the virtual node of the element.
  3. On line 58, need to use getRootNode for the correct lookup
  4. On line 69, we need to use the virtualNode.children array instead of node.childNodes and then in the for loop, make sure we are looking at the actualNode for each virtual child node.
  5. Finally, we need some tests that test all of these conditions

@marcysutton
Copy link
Contributor Author

@dylanb I've completed the changes and added some more tests. Ready for another review.

@@ -2,7 +2,7 @@

var nodeName = node.nodeName.toUpperCase(),
nodeType = node.type,
doc = document;
doc = axe.commons.dom.getRootNode(node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on line 40, the relevantNode can change and therefore the doc might change too for the lookup on line 43. I think this code should be moved to where the doc is actually being used

var shadowRoot = document.getElementById('parent').attachShadow({ mode: 'open' });
shadowRoot.innerHTML = '<div id="shadowParent">' +
'<label for="input" id="shadowLabel">Label' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another explicit label

});

it('should look at the children of a virtual node for overlap', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this test be one that overlaps and therefore returns false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the default CSS overlap since the text node is a child?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also that conditional returns true–I thought it was checking to see if there was overlapping content worth evaluating.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

assert.isTrue(rule.matches(firstChild, axe.utils.getNodeFromTree(tree[0], firstChild)));
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a test where the implicit label is in the light DOM and the input in the shadow DOM

fixture.innerHTML = '<label>Text<div id="firstChild"></div></label>'
...
shadowRoot.innerHTML = '<input id="shadowTarget" type="text" />'
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I was thinking of the disabled case where the input that is inside the shadow DOM is disabled and it gets excluded from the color contrast check - apologies for not being clear enough.

Copy link
Contributor Author

@marcysutton marcysutton Jul 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach I took with other tests was to put a second, enabled input in the light DOM with the same ID and an explicit pairing with the label–that way it would return true if the shadow boundary wasn't being handled properly. Otherwise it's difficult to test the isFalse case by itself since that would mean it didn't get matched (and could have occurred for any number of reasons). The problem with this one is the <label> is already in the light DOM, so it would get paired with the first input. for/id pairings also don't span shadow boundaries, because of scoping. So I'll find a different way to write this test.

@@ -40,41 +39,43 @@ if (nodeName === 'LABEL' || nodeParentLabel) {
relevantNode = nodeParentLabel;
}
// explicit label of disabled input
var doc = axe.commons.dom.getRootNode(node);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be var doc = axe.commons.dom.getRootNode(relevantNode);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, probably use let to block scope it

@marcysutton
Copy link
Contributor Author

@dylanb I've incorporated those two test changes, it's ready for another review.

@dylanb dylanb merged commit 3087e90 into shadowDOM Jul 13, 2017
@marcysutton marcysutton deleted the sd/color-contrast-matches branch July 15, 2017 15:37
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.

2 participants