Skip to content

Commit fa250d7

Browse files
committed
refactor: update SheetContent component to support dynamic portal container selection
1 parent eee525e commit fa250d7

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

src/client/components/ui/sheet.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,29 @@ interface SheetContentProps
5454
const SheetContent = React.forwardRef<
5555
React.ElementRef<typeof SheetPrimitive.Content>,
5656
SheetContentProps
57-
>(({ side = 'right', className, children, ...props }, ref) => (
58-
<SheetPortal>
59-
<SheetOverlay />
60-
<SheetPrimitive.Content
61-
ref={ref}
62-
className={cn(sheetVariants({ side }), className)}
63-
{...props}
64-
>
65-
{children}
66-
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none">
67-
<Cross2Icon className="h-4 w-4" />
68-
<span className="sr-only">Close</span>
69-
</SheetPrimitive.Close>
70-
</SheetPrimitive.Content>
71-
</SheetPortal>
72-
));
57+
>(({ side = 'right', className, children, ...props }, ref) => {
58+
const portalContainer =
59+
typeof document === 'undefined'
60+
? undefined
61+
: document.querySelector('.App') ?? undefined;
62+
63+
return (
64+
<SheetPortal container={portalContainer}>
65+
<SheetOverlay />
66+
<SheetPrimitive.Content
67+
ref={ref}
68+
className={cn(sheetVariants({ side }), className)}
69+
{...props}
70+
>
71+
{children}
72+
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none">
73+
<Cross2Icon className="h-4 w-4" />
74+
<span className="sr-only">Close</span>
75+
</SheetPrimitive.Close>
76+
</SheetPrimitive.Content>
77+
</SheetPortal>
78+
);
79+
});
7380
SheetContent.displayName = SheetPrimitive.Content.displayName;
7481

7582
const SheetHeader = ({

0 commit comments

Comments
 (0)