Skip to content
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

Feature request: Support Shadow DOM #828

Open
x0k opened this issue Oct 28, 2024 · 9 comments
Open

Feature request: Support Shadow DOM #828

x0k opened this issue Oct 28, 2024 · 9 comments
Labels
contributions welcome Open to contributions feature A feature request

Comments

@x0k
Copy link

x0k commented Oct 28, 2024

Describe the bug

The Select component does not open the options list when it mounted in shadow DOM.

  • bits-ui@next
  • I don't know if it works in the latest version
  • Also did not test other components with floating elements

GitHub Pages

Reproduction

https://github.com/x0k/bits-ui-shadow-dom-select

Logs

No response

System Info

System:
    OS: Linux 6.6 Manjaro Linux
    CPU: (12) x64 Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
    Memory: 4.77 GB / 15.56 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 22.9.0 - /nix/store/f9yl8nlgcyazflxc2nj1cr9k9ika7v7z-nodejs-22.9.0/bin/node
    npm: 10.8.3 - /nix/store/f9yl8nlgcyazflxc2nj1cr9k9ika7v7z-nodejs-22.9.0/bin/npm
  Browsers:
    Brave Browser: 130.1.71.118
  npmPackages:
    bits-ui: 1.0.0-next.31 => 1.0.0-next.31 
    svelte: ^5.1.3 => 5.1.3

Severity

annoyance

@huntabyte
Copy link
Owner

I'm not very familiar with the Shadow DOM tbh and would be looking for community assistance in ensuring this project can support it across all components. If this is something you could help with, it'd be greatly appreciated!

@huntabyte huntabyte added enhancement An improvement to an existing feature/component next labels Oct 28, 2024
@huntabyte
Copy link
Owner

Seems we could expose an optional prop to the various components call getRootNode where users can return their root node and it will default to the document.

@huntabyte huntabyte added the contributions welcome Open to contributions label Nov 17, 2024
@rxliuli
Copy link

rxliuli commented Jan 8, 2025

This also led to downstream errors of svelte shadcn/ui huntabyte/shadcn-svelte#1604

@huntabyte huntabyte added feature A feature request and removed enhancement An improvement to an existing feature/component labels Jan 29, 2025
@huntabyte huntabyte changed the title Select don't work in shadow DOM (next) Feature request: Support Shadow DOM Jan 29, 2025
@huntabyte huntabyte removed the next label Jan 29, 2025
@rxliuli
Copy link

rxliuli commented Jan 30, 2025

I noticed that support for shadow dom was abandoned 14 hours ago, so bits-ui 1.0 will no longer consider supporting shadow dom, right?

@x0k
Copy link
Author

x0k commented Jan 30, 2025

Note

This is not that hard to implement.
Initially the problem was in the useRefById function from the svelte-toolbelt library. Now you can pass the getRootNode argument to this function to work correctly with the shadow DOM.

In my opinion, one of the possible solutions is to define a global context with the getRootNode function and read its value before using useRefById.

@huntabyte
Copy link
Owner

I noticed that support for shadow dom was abandoned 14 hours ago, so bits-ui 1.0 will no longer consider supporting shadow dom, right?

It's not a blocker for 1.0; it can be added after stability without breaking change.

I'd still like to have it prior to 1.0.

@huntabyte
Copy link
Owner

In my opinion, one of the possible solutions is to define a global context with the getRootNode function and read its value before using useRefById.

Yeah this is the idea. Have a <BitsConfig> component that can handle that

@rxliuli
Copy link

rxliuli commented Jan 31, 2025

Initially the problem was in the useRefById function from the svelte-toolbelt library. Now you can pass the getRootNode argument to this function to work correctly with the shadow DOM.

However, the Sheet component still cannot work properly in the shadow DOM at present. After checking, I found that one of the errors was caused by not passing the getRootNode parameter when using useRefById in the use-dismissable-layer.svelte.ts file, which is an internal implementation (indirectly dependent on svelte-shadcn). I had to patch it locally using pnpm.

@huntabyte
Copy link
Owner

huntabyte commented Feb 1, 2025

After thinking on this a bit more, I believe once this lands: sveltejs/svelte#15000 we'll be able to get a reference to the node without needing to specify an id which also means we can get the node's owner document to seamlessly support shadow DOM without needing to create a global provider of sorts.

At that point, the useRefById function would end up being an anonymous attachment that sets a reference to the node in internal Bits state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome Open to contributions feature A feature request
Projects
None yet
Development

No branches or pull requests

3 participants