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

hideOthers hides everything when target is in Shadow DOM and paren is not explicitly provided #14

Closed
harunurhan opened this issue Nov 8, 2022 · 2 comments
Assignees

Comments

@harunurhan
Copy link

harunurhan commented Nov 8, 2022

Traversal to mark all parent chain of as "elementToKeep" gets stuck at shadow root since it's using element.parentNode, so no top level parent (direct child of body) is reached.

keep(el.parentNode!);

And since it's using target.ownerDocument.body to start setting aria-hidden: "true", it just stops after hiding all of its children, which is pretty much everything on the page :(

return sampleTarget.ownerDocument.body;

Consumer can indeed address this issue manually, but maybe we could change the default getDefaultParent to return shadow root to make this easier for everyone, since not all will notice this is broken.

const getDefaultParent = (originalTarget: Element | Element[]): HTMLElement | null => {

Maybe something like that could work?

const rootNode = element.getRootNode();
const isShadowRoot = rootNode instanceof ShadowRoot;
return isShadowRoot ? rootNode : element.owerDocument.body;

However in some cases if not most, I don't think hiding everything only within a shadow DOM is going to work, so it could be better to fix parent traversal.

keep(el.parentNode ?? el.host);
@theKashey
Copy link
Owner

  • check if parent contains target
  • if not
    • if there is owner document - move target there
      • repeat
    • display warning. If parent equal to the body - do nothing (we really don't want to "hide" everything)

This should "bubble up" target to current document, po

@theKashey
Copy link
Owner

Resolved in v1.2.2

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

No branches or pull requests

2 participants