GoogleChrome / accessibility-developer-tools

This is a library of accessibility-related testing and utility code.
Apache License 2.0
2.27k stars 359 forks source link

handle nodes hosted in a <template> #338

Closed valdrinkoshi closed 7 years ago

valdrinkoshi commented 7 years ago

Fixes #337. @alice FYI

valdrinkoshi commented 7 years ago

@alice I've realized the issue happens only if a node is hosted in a <template>, because if we use a DocumentFragment to host nodes and then add the fragment to the main document, the parent of each node will be the new parent, not the DocumentFragment. This is not the case for <template>:

var frag = document.createDocumentFragment();
frag.appendChild(document.createElement('div'));
document.body.appendChild(frag); // the <div>.parentNode is <body>

var templ = document.createElement('template');
templ.content.appendChild(document.createElement('div'));
document.body.appendChild(templ); // the <div>.parentNode is <template>.content!

I've updated the test and the implementation to handle specifically <template>, PTAL 🍰

addyosmani commented 7 years ago

LGTM2