Repository navigation
fix(shadow-dom): shadow-safe FocusScope, per-root focus guards, retarget-safe listeners - #2794
Merged
Merged
Conversation
…er cursor ScrollArea: document wheel listener reads the composed target (getEventTarget) so wheel-over-scrollbar works in a shadow root; body user-select via getOwnerDocument. Select: document pointerup containment reads the composed target. Splitter cursor now injects via the shared injectStyle helper (nonce-threaded). Tooltip/HoverCard contains-sites already shadow-safe (DismissableLayer composes the target / element-level listeners). Refs #2725 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
FocusScope attaches focusin/focusout to the container's root (ShadowRoot in a web component) so targets aren't retargeted to the host, PLUS a document focusin fallback — a focusout recall loses the race to the pending focus commit, so the recall that actually wins is the document focusin (which a shadow-root listener never sees). Adds containsComposed() for the composed-target scope check. In light DOM (root === ownerDocument) behavior is unchanged. useFocusGuards gains an optional element param: guards are refcounted per root (WeakMap) and placed at the ShadowRoot edges when scoped; FocusGuards.vue stays document-body (back-compat). The 4 content components (Combobox/Popover/Menu/Select) pass currentElement so a shadow-mounted trap's edge guards are visible to it. Verified via jsdom probes: intra-shadow moves don't yank, escapes recall into the scope, removed-element recovers. Full suite (2033) green. Body scroll lock is unchanged — a shadow root shares the host document body, which it already locks. Refs #2725 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… limits Refs #2725 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughChangesShadow DOM support
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Member
Author
|
@CodeRabbit review |
Contributor
✅ Action performedReview finished.
|
zernonia
added a commit
that referenced
this pull request
Jul 18, 2026
…2796) * feat(Menu): headless composables for the Menu overlay family Converts the core Menu parts to compose a useMenu.ts module, validating the overlay archetype for #2723 (after Switch + Tabs). Public API unchanged. - useMenuRoot() — state-only overlay root: returns { open, onOpenChange, onClose } + the MenuContext/MenuRootContext objects the SFC provides. No PartSurface (the root renders no attrs). MenuRoot.vue composes it. - getMenuItemBaseSurface() — the attr-bearing item render surface (role/aria/highlight handlers). A context-SCOPED factory (creates per-instance isFocused, needs the item element) — the Tabs pure-builder axiom does not hold for overlays. MenuItemImpl.vue. - getMenuItemSelectSurface() — the close-on-select protocol via an onSelect callback channel (the CustomEvent token, never a merged DOM listener). MenuItem.vue. - useMenuContent() — the overlay brain: typeahead, arrow-nav, the pointer-grace machine, highlightedElement ownership. Returns the role=menu surface + the content context; the four component wrappers and the two mount side-effects stay in the SFC. Cuts MenuContentImpl.vue from 405 to 191 lines; the only un-extractable seam is RovingFocusGroup.getItems() (a template-instance ref), injected as a getItems option. Surfaces bind via mergeProps so consumer listeners chain; functional data-* selectors (data-reka-menu-content) live in props, not stateToDataAttrs. useFocusGuards stays scoped to the content root (#2794). Menu + DropdownMenu + ContextMenu + Menubar 56/56 green; full suite 2075 green; type-check clean; 19 useMenu unit tests. Refs #2723 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(Menu): overlay-family findings + recipe overlay section Refs #2723 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8 tasks
This was referenced Sep 4, 2026
Closed
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second and final part of shadow-DOM support (
Refs #2725). Part 1 (#2792) landed the shared helpers (getRootNode/getOwnerDocument/getEventTarget/getElementByIdFrom/injectStyle/…). This PR wires the remaining components that still assumed the light DOM, so an open shadow-rooted component actually works — most importantly the focus trap.What changed
FocusScope — shadow-safe trap (
FocusScope.vue,getRootNode.ts)focusin/focusoutto the container's root (theShadowRootin a web component) so event targets aren't retargeted to the host, plus adocumentfocusinfallback: afocusout-driven recall loses the race to the pending focus commit, and the recall that actually wins fires as adocumentfocusin— which a shadow-root listener never sees.containsComposed()for the composed-target scope-membership check across shadow boundaries.root === ownerDocument) behavior is unchanged.Focus guards — per-root (
useFocusGuards.ts+ 4 callers)useFocusGuards(element?)refcounts guards per root (WeakMap) and places them at theShadowRootedges when scoped; the default (no arg) stays document-body for back-compat.currentElementso a shadow-mounted trap's edge guards live inside the same root.Retarget-safe listeners + injected styles
ScrollAreaScrollbarImpl/SelectContentImpl: document-level wheel/pointer handlers read the composed target so a shadow-mounted content isn't mistaken for "outside" itself; body user-select toggles viagetOwnerDocument.Splittercursor: global cursor style now goes throughinjectStyle(per-document, nonce-aware) instead of a module-global<style>.Body scroll lock — intentionally unchanged. A shadow root shares the host
document.body, which is the correct scroll surface, souseBodyScrollLockneeds no scoping.Known limitations (documented in CONTRIBUTING)
Portalled content still defaults to
body(outside the root) unlessConfigProvider'steleportTopoints inside the shadow root; closed shadow roots, cross-boundary aria idrefs for teleported content,HoverCardselection/scroll (composed: false),useHideOthers, and the iOStouchmoveoverflow walk remain browser-only / genuinely unfixable.Testing
useFocusGuards(back-compat + per-root refcount at shadow edges).type-checkclean.Refs #2725
Summary by CodeRabbit
Bug Fixes
Documentation