Skip to content

Focus isn't working when Shadow DOM is usedΒ #6033

@denisorehovsky

Description

@denisorehovsky

Provide a general summary of the issue here

I have a web component built with react and react-to-web-component library. The problem is Shadow DOM and data-focused="true" for selects and some other elements as well.

data-focused="true" doesn't work inside of Shadow DOM. It works only when I disable Shadow DOM:
image

import r2wc from "@r2wc/react-to-web-component";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import React from "react";
import App from "./app";
import "./index.scss";

const queryClient = new QueryClient();

type CalendarProps = {
  container: ShadowRoot;
};

const CalendarComponent: React.FC<CalendarProps> = (props: CalendarProps) => {
  const link = document.createElement("link");
  link.setAttribute("rel", "stylesheet");
  link.setAttribute("href", "/static/visual-rates-tape/style.css");
  props.container.appendChild(link);

  return (
    <React.StrictMode>
      <QueryClientProvider client={queryClient}>
        <App />
        <ReactQueryDevtools initialIsOpen={false} />
      </QueryClientProvider>
    </React.StrictMode>
  );
};

if (!customElements.get("calendar-component")) {
  customElements.define(
    "calendar-component",
    r2wc(CalendarComponent, {
      props: { container: "json" },
      // shadow: "open",
    }),
  );
}

πŸ€” Expected Behavior?

The select should focused like on the screenshot (disabled Shadow DOM)
image

😯 Current Behavior

The select is not focused (enabled Shadow DOM).
image

πŸ’ Possible Solution

No response

πŸ”¦ Context

No response

πŸ–₯️ Steps to Reproduce

Add a select input inside of shadow-root (open).

Version

react-aria-components v1.1.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Mac

🧒 Your Company/Team

No response

πŸ•· Tracking Issue

No response

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