Constconst [dialogEl, setDialogEl] = useState<HTMLDivElement | null>(null);
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogContent ref={setDialogEl}>
<PopoverPortalContainerProvider container={dialogEl}>
<BookChapterControl ... />
</PopoverPortalContainerProvider>
</DialogContent>
</Dialog>;
Keeps descendant PopoverContent inside
containerinstead ofdocument.body. Use it whenever a popover's trigger sits inside an ancestor that owns a focus trap or a dismiss-on-outside-click layer (DialogContent,DropdownMenuContent, …), which would otherwise pull focus out of the popover or treat a click inside it as an outside click.Contract:
nullforcontaineruntil the ancestor element exists (the initial state of a ref-callbackuseState) to keep Radix'sdocument.bodydefault; once it exists, later opens portal into it.TooltipPortalContainerProviderintooltip.tsxdoes the same for tooltips.