Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(ui): support owned Select portal containers (#8437)

Andrew Huang7fefcb5671c0
diff --git a/frontend/src/components/v3/generic/Select/Select.stories.tsx b/frontend/src/components/v3/generic/Select/Select.stories.tsx
index 5c0cefa498..9222d2f779 100644
--- a/frontend/src/components/v3/generic/Select/Select.stories.tsx
+++ b/frontend/src/components/v3/generic/Select/Select.stories.tsx
@@ -2,8 +2,11 @@ import { useState } from "react";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { CloudIcon, KeyIcon, LockIcon, ServerIcon, ShieldIcon } from "lucide-react";
+import { Button } from "../Button";
+import { Dialog, DialogContent, DialogDescription, DialogTitle, DialogTrigger } from "../Dialog";
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from "../Field";
import { Input } from "../Input";
+import { Sheet, SheetContent, SheetDescription, SheetTitle, SheetTrigger } from "../Sheet";
import {
Select,
SelectContent,
@@ -530,3 +533,95 @@ export const LongList: Story = {
</Select>
)
};
+
+function NestedForm({ containerPortal = false }: { containerPortal?: boolean }) {
+ const [container, setContainer] = useState<HTMLFormElement | null>(null);
+ const [submitted, setSubmitted] = useState("");
+
+ return (
+ <form
+ ref={setContainer}
+ className="flex flex-col gap-4"
+ onSubmit={(event) => {
+ event.preventDefault();
+ const data = new FormData(event.currentTarget);
+ setSubmitted(`${data.get("name")}: ${data.get("region")}`);
+ }}
+ >
+ <Field>
+ <FieldLabel htmlFor="nested-select-name">Name</FieldLabel>
+ <Input id="nested-select-name" name="name" defaultValue="Demo service" required />
+ </Field>
+ <Field>
+ <FieldLabel htmlFor="nested-select-region">Region</FieldLabel>
+ <Select name="region" defaultValue="region-1">
+ <SelectTrigger id="nested-select-region" className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent
+ position="popper"
+ portalContainer={containerPortal ? container : undefined}
+ >
+ {Array.from({ length: 30 }, (_, index) => (
+ <SelectItem key={index} value={`region-${index + 1}`}>
+ Region {index + 1}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
+ <Button type="submit">Save</Button>
+ <output aria-live="polite">{submitted}</output>
+ </form>
+ );
+}
+
+export const InsideDialog: Story = {
+ name: "Example: Inside Dialog",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ "Keep the default body portal for V3 Dialogs, including scrollable content. Escape closes the Select first and restores its trigger focus; a subsequent Escape closes the Dialog. The native named Select value is included in the parent form submission."
+ }
+ }
+ },
+ render: () => (
+ <Dialog>
+ <DialogTrigger asChild>
+ <Button variant="outline">Open Dialog</Button>
+ </DialogTrigger>
+ <DialogContent>
+ <DialogTitle>Service Region</DialogTitle>
+ <DialogDescription>Choose a region for this demo service.</DialogDescription>
+ <NestedForm />
+ </DialogContent>
+ </Dialog>
+ )
+};
+
+export const InsideSheet: Story = {
+ name: "Example: Owned Portal Container",
+ parameters: {
+ docs: {
+ description: {
+ story:
+ "SelectContent accepts portalContainer using Radix Portal's container type. For a retained legacy overlay, attach a stable callback ref to the caller's existing form and pass that element as portalContainer with position=\"popper\". Item-aligned positioning assumes viewport coordinates and does not support transformed containers. Choose a container that will not clip the popup; do not portal into scrolling or clipping containers. V3 Dialogs and Sheets normally need no opt-in and should retain the default body portal. This example portals into the actual form without changing layer tokens or dismissal behavior."
+ }
+ }
+ },
+ render: () => (
+ <Sheet>
+ <SheetTrigger asChild>
+ <Button variant="outline">Open Sheet</Button>
+ </SheetTrigger>
+ <SheetContent>
+ <div className="flex flex-col gap-4 p-6">
+ <SheetTitle>Service Region</SheetTitle>
+ <SheetDescription>Choose a region for this demo service.</SheetDescription>
+ <NestedForm containerPortal />
+ </div>
+ </SheetContent>
+ </Sheet>
+ )
+};
diff --git a/frontend/src/components/v3/generic/Select/Select.tsx b/frontend/src/components/v3/generic/Select/Select.tsx
index 5b4a31d572..9eaca73f60 100644
--- a/frontend/src/components/v3/generic/Select/Select.tsx
+++ b/frontend/src/components/v3/generic/Select/Select.tsx
@@ -113,10 +113,13 @@ function SelectContent({
position = "item-aligned",
align = "center",
collisionPadding = 8,
+ portalContainer,
...props
-}: React.ComponentProps<typeof SelectPrimitive.Content>) {
+}: React.ComponentProps<typeof SelectPrimitive.Content> & {
+ portalContainer?: React.ComponentProps<typeof SelectPrimitive.Portal>["container"];
+}) {
return (
- <SelectPrimitive.Portal>
+ <SelectPrimitive.Portal container={portalContainer}>
<SelectPrimitive.Content
data-slot="select-content"
data-align-trigger={position === "item-aligned"}