Fix outside click detection when component is mounted in the Shadow DOM (#2866)

* Fix outside click detection when component is mounted in the Shadow DOM

* Fix code style

* Fix error
This commit is contained in:
Jordan Pittman
2023-12-05 11:20:37 -05:00
committed by GitHub
parent 24486b39ca
commit 7b30e06088
3 changed files with 146 additions and 123 deletions
@@ -43,6 +43,7 @@ export function useRootContainers({
if (!(container instanceof HTMLElement)) continue // Skip non-HTMLElements
if (container.id === 'headlessui-portal-root') continue // Skip the Headless UI portal root
if (container.contains(mainTreeNodeRef.current)) continue // Skip if it is the main app
if (container.contains((mainTreeNodeRef.current?.getRootNode() as ShadowRoot)?.host)) continue // Skip if it is the main app (and the component is inside a shadow root)
if (containers.some((defaultContainer) => container.contains(defaultContainer))) continue // Skip if the current container is part of a container we've already seen (e.g.: default container / portal)
containers.push(container)