-
-
Notifications
You must be signed in to change notification settings - Fork 233
fix: account for shadow-dom in activeElement checks #2697
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
Conversation
…e focus separately
This reverts commit 4fbcc0a.
🦋 Changeset detectedLatest commit: a51a77c The changes in this PR will be included in the next version bump. This PR includes changesets to release 77 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| export function isActiveElement(element: Element | null | undefined): boolean { | ||
| if (!element) return false | ||
| const rootNode = element.getRootNode() as Document | ShadowRoot | ||
|
|
||
| return getActiveElement(rootNode) === element | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if this function should be used in the createScope functions or not. Currently those check both whether the element is active and within the scope root. Is that intentional? It seems to me like that would be fragile e.g. if the component uses some kind of portals or renders something outside the scope root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my thought as well. So yes, let’s add it to the scope and use the scope everywhere if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #
📝 Description
activeElementchecks are sometimes done usingdocument.activeElement !== element, which is an issue for apps containing shadow-dom elements such as web-components. This prevents Zag from being used in e.g. default Lit setups (#2681).isActiveElementto@zag-js/dom-queryfor consistent activeElement checks.getActiveElementis tweaked to allow for focusable (tabindex="0") web components that do not contain⛳️ Current behavior (updates)
Focus trap and other utilities / machines do not find the focused elment within a shadow-dom root, resulting in unwanted behaviour.
🚀 New behavior
Focused elements are consistently found.
💣 Is this a breaking change (Yes/No):
No
📝 Additional Information