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

Add include shadow element #3765

Closed
ccheung0926 opened this issue Nov 1, 2022 · 6 comments · Fixed by #3798
Closed

Add include shadow element #3765

ccheung0926 opened this issue Nov 1, 2022 · 6 comments · Fixed by #3798
Labels
core Issues in the core code (lib/core) feat New feature or enhancement
Milestone

Comments

@ccheung0926
Copy link

Product

axe-core

Question

Hi,

I am currently working on a project for my company and would like to know how I can add my shadow element under the include selector list?

@ccheung0926 ccheung0926 added question ungroomed Ticket needs a maintainer to prioritize and label labels Nov 1, 2022
@straker
Copy link
Contributor

straker commented Nov 1, 2022

Currently this isn't possible. We had a ticket for it, but closed it due to lack of use cases. Do you have a use case for doing this?

@straker straker removed the ungroomed Ticket needs a maintainer to prioritize and label label Nov 1, 2022
@ccheung0926
Copy link
Author

hi @straker
Yes, I saw that ticket. And I would like to say we have a use case for it. I am not in the position to expose too much information here. But my company's accessibility team has a roadmap to integrate with Axe-core. The product team uses lit library which is very heavy on shadow DOM.
It would be great if I can choose shadow DOM as part of the inclusive/exclusive shadow DOM selector prior to the Axe-core scan.

@straker
Copy link
Contributor

straker commented Nov 1, 2022

I think the best you could do at the moment is select the top-most custom element that has the shadow DOM. We can leave this ticket open for now now that we have a use case for it and start exploring it again.

@ccheung0926
Copy link
Author

@straker Sure, i can use the top-most custom element for now. But just let you know that that top-most element is a parent that nested with a lot of shadow DOMs developed by different UI teams 😅

@WilcoFiers
Copy link
Contributor

I think this would be a good thing for us to resolve. For now there is a workaround you could use. You can include DOM nodes, including shadow nodes. If you wanted you could create a little shadowRoot query function. Something like this:

function getShadowNode(...queries) {
  let node, query;
  while (query = queries.shift()) {
    node = (node?.shadowRoot ?? node ?? document)
      .querySelector(query);
  }
  return node;
}
const shadowNode = getShadowNode('#shadow-root', '#nested-elm', '#my-team')
axe.run(shadowNode);

@WilcoFiers WilcoFiers added this to the Axe-core 4.6 milestone Nov 4, 2022
@WilcoFiers WilcoFiers added feat New feature or enhancement core Issues in the core code (lib/core) and removed question labels Nov 4, 2022
@WilcoFiers
Copy link
Contributor

In hindsight... axe-core has a utility function that lets you select individual nodes from shadow DOM trees that will work today:

const shadowNode = axe.utils.shadowSelect('#shadow-root', '#nested-elm', '#my-team')
axe.run(shadowNode);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues in the core code (lib/core) feat New feature or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants