-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Shadow DOM support #828
Comments
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! |
Seems we could expose an optional prop to the various components call |
This also led to downstream errors of svelte shadcn/ui huntabyte/shadcn-svelte#1604 |
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? |
Note This is not that hard to implement. In my opinion, one of the possible solutions is to define a global context with the |
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. |
Yeah this is the idea. Have a |
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 |
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 At that point, the |
Just sharing the current temporary solution, which is basically patching the svelte-toolbelt module. Special thanks to @MichaelBrunn3r for the explanation 1. pnpm patch svelte-toolbelt
code node_modules/.pnpm_patches/[email protected]/dist/utils/use-ref-by-id.svelte.js
# paste code
pnpm patch-commit './node_modules/.pnpm_patches/[email protected]' // node_modules/.pnpm_patches/[email protected]/dist/utils/use-ref-by-id.svelte.js
import { watch } from "runed";
import { onDestroyEffect } from "./on-destroy-effect.svelte.js";
import { getContext } from "svelte";
function getRootNodeFromContext() {
return getContext("ShadcnConfig")?.portal;
}
/**
* Finds the node with that ID and sets it to the boxed node.
* Reactive using `$effect` to ensure when the ID or deps change,
* an update is triggered and new node is found.
*/
export function useRefById({ id, ref, deps = () => true, onRefChange, getRootNode }) {
watch([() => id.current, deps], ([_id]) => {
const rootNode = getRootNode?.() ?? getRootNodeFromContext() ?? document;
const node = rootNode?.querySelector(`#${_id}`);
if (node)
ref.current = node;
else
ref.current = null;
onRefChange?.(ref.current);
});
onDestroyEffect(() => {
ref.current = null;
onRefChange?.(null);
});
} Then set the context in your root component like layout.svelte or app.svelte. <script lang="ts">
import { setContext } from 'svelte'
setContext(
'ShadcnConfig',
document
.querySelector('custom-element')
?.shadowRoot?.querySelector('body')!,
)
</script> Footnotes |
Describe the bug
The Select component does not open the options list when it mounted in shadow DOM.
bits-ui@next
latest
versionGitHub Pages
Reproduction
https://github.com/x0k/bits-ui-shadow-dom-select
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: