(props: { children?: ReactNode })
| 12 | * whether a FormKit input is booting in a Document or ShadowRoot. |
| 13 | */ |
| 14 | export function FormKitRoot(props: { children?: ReactNode }) { |
| 15 | const boundary = useRef<HTMLSpanElement | null>(null) |
| 16 | const [root, setRoot] = useState<Document | ShadowRoot | undefined>(undefined) |
| 17 | |
| 18 | useLayoutEffect(() => { |
| 19 | const boundaryNode = boundary.current |
| 20 | if (!boundaryNode) return |
| 21 | const nextRoot = boundaryNode.getRootNode() |
| 22 | const isShadowRoot = |
| 23 | typeof ShadowRoot !== 'undefined' && nextRoot instanceof ShadowRoot |
| 24 | if (isShadowRoot || nextRoot instanceof Document) { |
| 25 | setRoot(nextRoot) |
| 26 | } |
| 27 | }, []) |
| 28 | |
| 29 | if (!root) { |
| 30 | return createElement('span', { |
| 31 | ref: boundary, |
| 32 | style: { display: 'none' }, |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | return createElement(rootSymbol.Provider, { value: root }, props.children) |
| 37 | } |
| 38 | |
| 39 | export { rootSymbol } |
nothing calls this directly
no test coverage detected