Skip to content

Commit

Permalink
passthrough ownerDocument to <Portal>
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Dec 12, 2024
1 parent 6743015 commit 1f756a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,7 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
actions.setOptionsElement,
setLocalOptionsElement
)
let portalOwnerDocument = useOwnerDocument(data.buttonElement || data.inputElement)
let ownerDocument = useOwnerDocument(data.optionsElement)

let usesOpenClosedState = useOpenClosed()
Expand Down Expand Up @@ -1819,7 +1820,7 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
let render = useRender()

return (
<Portal enabled={portal ? props.static || visible : false}>
<Portal enabled={portal ? props.static || visible : false} ownerDocument={portalOwnerDocument}>
<ComboboxDataContext.Provider
value={data.mode === ValueMode.Multi ? data : { ...data, isSelected }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
let data = useData('Listbox.Options')
let actions = useActions('Listbox.Options')

let portalOwnerDocument = useOwnerDocument(data.buttonElement)
let ownerDocument = useOwnerDocument(data.optionsElement)

let usesOpenClosedState = useOpenClosed()
Expand Down Expand Up @@ -1163,7 +1164,7 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>(
let render = useRender()

return (
<Portal enabled={portal ? props.static || visible : false}>
<Portal enabled={portal ? props.static || visible : false} ownerDocument={portalOwnerDocument}>
<ListboxDataContext.Provider
value={data.mode === ValueMode.Multi ? data : { ...data, isSelected }}
>
Expand Down
3 changes: 2 additions & 1 deletion packages/@headlessui-react/src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ function ItemsFn<TTag extends ElementType = typeof DEFAULT_ITEMS_TAG>(
useEvent((element) => dispatch({ type: ActionTypes.SetItemsElement, element })),
setLocalItemsElement
)
let portalOwnerDocument = useOwnerDocument(state.buttonElement)
let ownerDocument = useOwnerDocument(state.itemsElement)

// Always enable `portal` functionality, when `anchor` is enabled
Expand Down Expand Up @@ -824,7 +825,7 @@ function ItemsFn<TTag extends ElementType = typeof DEFAULT_ITEMS_TAG>(
let render = useRender()

return (
<Portal enabled={portal ? props.static || visible : false}>
<Portal enabled={portal ? props.static || visible : false} ownerDocument={portalOwnerDocument}>
{render({
ourProps,
theirProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(
useEvent((panel) => dispatch({ type: ActionTypes.SetPanel, panel })),
setLocalPanelElement
)
let portalOwnerDocument = useOwnerDocument(state.button)
let ownerDocument = useOwnerDocument(internalPanelRef)

useIsoMorphicEffect(() => {
Expand Down Expand Up @@ -1080,7 +1081,10 @@ function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(
<ResetOpenClosedProvider>
<PopoverPanelContext.Provider value={id}>
<PopoverAPIContext.Provider value={{ close, isPortalled }}>
<Portal enabled={portal ? props.static || visible : false}>
<Portal
enabled={portal ? props.static || visible : false}
ownerDocument={portalOwnerDocument}
>
{visible && isPortalled && (
<Hidden
id={beforePanelSentinelId}
Expand Down

0 comments on commit 1f756a3

Please sign in to comment.