Skip to content

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

@harunurhan

Description

@harunurhan

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions