Skip to content

[Bug] Selector, DropdownMenu, and ContextMenu ignore option clicks inside a shadow root #7908

Closed

Description

@faysou

Description

Inside a shadow root, clicking an option in a Selector closes the list without selecting the option. DropdownMenu and ContextMenu share the cause, since they use the same useMenuPress hook. Keyboard selection works.

useMenuPress finds the element under the released pointer with document.elementFromPoint (useMenuPress.ts L366-L367):

} else if (typeof doc.elementFromPoint === 'function') {
  element = doc.elementFromPoint(event.clientX, event.clientY);

For a point inside a shadow root, document.elementFromPoint returns the shadow host, not the option. root.contains(element) is then false, so resolvePoint reports the release as outside the menu, and the hook dismisses the menu instead of activating the option.

I expected the option under the pointer to be selected, as it is outside a shadow root.

Reproduction

  1. Render a Selector inside an open shadow root, for example createRoot(host.attachShadow({mode: 'open'})) with the Astryx CSS adopted into the shadow root.
  2. Open the selector and click an option with the mouse.
  3. The list closes and the value does not change.

With the pointer over an option, the page reports:

document.elementFromPoint(x, y);              // the shadow host element
host.shadowRoot.elementFromPoint(x, y);       // the option's <span>

I hit this with Astryx widgets in marimo, which renders each notebook widget inside a shadow root. The same widgets work in JupyterLab, which does not use a shadow root.

A local patch that hit-tests in the menu's own root fixes it:

element = (menu?.getRootNode() instanceof ShadowRoot ? menu.getRootNode() : doc)
  .elementFromPoint(event.clientX, event.clientY);

ShadowRoot implements elementFromPoint, and outside a shadow root getRootNode() returns the document, so behavior there is unchanged.

Astryx Version

@astryxdesign/[email protected], and the same code is on main at d421aed.

Environment

Chromium from Playwright 1.64.0, macOS 26.6.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions