Skip to content

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

improvement(ui): support Sheet and in-place Combobox creation (#8621)

Andrew Huang138028603afc
diff --git a/frontend/src/components/V3_MIGRATION.md b/frontend/src/components/V3_MIGRATION.md
index 579cf3fb49..60c6b8eb28 100644
--- a/frontend/src/components/V3_MIGRATION.md
+++ b/frontend/src/components/V3_MIGRATION.md
@@ -182,6 +182,14 @@ Use this recipe for every V2 `Modal`, `DeleteActionModal`, and `ConfirmActionMod
V2 controls rendered inside the overlay move to V3 in the same change. A V2 `Select`, `FilterableSelect`, `Dropdown`, or `Tooltip` inside a V3 overlay does not join the layer contract. `FilterableSelect` becomes `Combobox`. Remove caller-owned `onPopupOpenChange` registries that only guard the parent Escape.
+**Creating an option with a form.** Dialog creation renders `DialogHeader` followed by `renderForm`. Return `<form className="flex min-h-0 flex-1 flex-col gap-6">` with `DialogBody` for fields and `DialogFooter` for actions. Do not pad the whole form or replace the footer with an inset button row. The dialog shell supplies its padding and the footer extends to its edges, as in the Dialog stories.
+
+Use `creation.mode = "sheet"` for multi-step forms, with the existing Sheet `size` (`form`, `wide`, or `workspace`). It uses the same `renderForm({ initialInput, complete, cancel })`, `isPending`, and `onDismiss(cancel)` contract as dialog creation. Return form content with a scrollable body and `SheetFooter`, not another `Sheet` or `SheetContent`. The default header requires `title` and `description`. Set `showHeader: false` when the form owns its header, and provide `SheetHeader`, `SheetTitle`, and `SheetDescription` inside `renderForm` for the accessible name and description. Follow the Header → body → Footer composition and body padding in the Sheet stories.
+
+Use one caller-owned pending state for the form and `creation.isPending`, including sub-wizard persistence. Route `onDismiss` and the form's Cancel through the same discard guard. Update controlled options and selection before calling `complete`. Completion closes the creation overlay and returns focus to the Combobox input. Cancel preserves the query and reopens the option popup without changing the selection. See `Combobox.creation.stories.tsx` for canonical dialog and sheet compositions.
+
+**Starting an in-place creation workflow.** Use `creation.mode = "action"` with `onAction(inputValue)` when the existing form switches into a sub-wizard without opening another overlay. The Create row remains available for empty, duplicate, and unmatched queries unless `isDisabled` is set. Selection closes only the picker and calls `onAction` with the trimmed query. This mode does not persist, track pending work, or select an option; the caller owns the workflow and any later option/selection updates.
+
Before:
```tsx
diff --git a/frontend/src/components/v3/generic/Combobox/Combobox.creation.stories.tsx b/frontend/src/components/v3/generic/Combobox/Combobox.creation.stories.tsx
new file mode 100644
index 0000000000..acbde7559d
--- /dev/null
+++ b/frontend/src/components/v3/generic/Combobox/Combobox.creation.stories.tsx
@@ -0,0 +1,456 @@
+import { useRef, useState } from "react";
+import type { Meta, StoryObj } from "@storybook/react-vite";
+
+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";
+
+import { DiscardChangesAlertDialog } from "../AlertDialog/DiscardChangesAlertDialog";
+import { Button } from "../Button";
+import {
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger
+} from "../Dialog";
+import { Field, FieldLabel } from "../Field";
+import { Input } from "../Input";
+import {
+ Sheet,
+ SheetClose,
+ SheetContent,
+ SheetDescription,
+ SheetFooter,
+ SheetHeader,
+ SheetTitle,
+ SheetTrigger
+} from "../Sheet";
+import { Stepper, StepperList, StepperStep } from "../Stepper";
+import { Combobox, type ComboboxFormCreationRenderProps } from ".";
+
+type Profile = { id: string; name: string };
+const PROFILES: Profile[] = [{ id: "existing", name: "Existing Profile" }];
+const ISSUERS: Profile[] = [
+ { id: "internal", name: "Internal CA" },
+ { id: "external", name: "External CA" }
+];
+const STEPS = ["Details", "Issuer", "Review"];
+
+type ProfileFormProps = ComboboxFormCreationRenderProps & {
+ showHeader: boolean;
+ isPending: boolean;
+ onPendingChange: (pending: boolean) => void;
+ onDirtyChange: (dirty: boolean) => void;
+ onCreated: (profile: Profile) => void;
+};
+
+const ProfileForm = ({
+ initialInput,
+ complete,
+ cancel,
+ showHeader,
+ isPending,
+ onPendingChange,
+ onDirtyChange,
+ onCreated
+}: ProfileFormProps) => {
+ const [name, setName] = useState(initialInput);
+ const [issuer, setIssuer] = useState<Profile | null>(null);
+ const [step, setStep] = useState(0);
+
+ const finishSave = () => {
+ onCreated({ id: name.trim(), name: name.trim() });
+ onDirtyChange(false);
+ onPendingChange(false);
+ complete();
+ };
+
+ return (
+ <>
+ {!showHeader && (
+ <SheetHeader>
+ <SheetTitle>Create Certificate Profile</SheetTitle>
+ <SheetDescription>
+ Configure a profile before attaching it to the application.
+ </SheetDescription>
+ </SheetHeader>
+ )}
+ <form
+ className="flex min-h-0 flex-1 flex-col"
+ onSubmit={(event) => {
+ event.preventDefault();
+ if (step === 2 && !isPending) onPendingChange(true);
+ }}
+ >
+ <div className="flex min-h-0 flex-1 overflow-hidden">
+ <aside className="w-60 shrink-0 border-r border-border p-4">
+ <Stepper
+ activeStep={step}
+ onStepChange={(nextStep) => {
+ if (!isPending) setStep(nextStep);
+ }}
+ >
+ <StepperList>
+ {STEPS.map((title, index) => (
+ <StepperStep key={title} index={index} title={title} />
+ ))}
+ </StepperList>
+ </Stepper>
+ </aside>
+ <div className="min-w-0 flex-1 overflow-y-auto p-4">
+ <h2 className="mb-6 font-alliance text-lg">{STEPS[step]}</h2>
+ {step === 0 && (
+ <Field>
+ <FieldLabel htmlFor="profile-name">Profile Name</FieldLabel>
+ <Input
+ id="profile-name"
+ value={name}
+ disabled={isPending}
+ onChange={(event) => {
+ setName(event.target.value);
+ onDirtyChange(true);
+ }}
+ />
+ </Field>
+ )}
+ {step === 1 && (
+ <Field>
+ <FieldLabel htmlFor="profile-issuer">Issuing CA</FieldLabel>
+ <Combobox
+ id="profile-issuer"
+ options={ISSUERS}
+ value={issuer}
+ onValueChange={(value) => {
+ setIssuer(value);
+ onDirtyChange(true);
+ }}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ isDisabled={isPending}
+ />
+ </Field>
+ )}
+ {step === 2 && (
+ <p>
+ {name} will use {issuer?.name}.
+ </p>
+ )}
+ </div>
+ <aside className="w-64 shrink-0 border-l border-border p-4 text-sm text-muted">
+ <p>This synthetic form uses the shared Sheet, Stepper, and Combobox.</p>
+ {isPending && (
+ <Button className="mt-4" variant="outline" onClick={finishSave}>
+ Finish Simulated Save
+ </Button>
+ )}
+ </aside>
+ </div>
+ <SheetFooter>
+ <Button variant="ghost" onClick={cancel} isDisabled={isPending}>
+ Cancel
+ </Button>
+ {step > 0 && (
+ <Button variant="outline" onClick={() => setStep(step - 1)} isDisabled={isPending}>
+ Back
+ </Button>
+ )}
+ {step < 2 ? (
+ <Button
+ key="next"
+ variant="project"
+ onClick={() => setStep(step + 1)}
+ isDisabled={!name.trim() || (step === 1 && !issuer) || isPending}
+ >
+ Next
+ </Button>
+ ) : (
+ <Button key="create" type="submit" variant="project" isPending={isPending}>
+ Create Profile
+ </Button>
+ )}
+ </SheetFooter>
+ </form>
+ </>
+ );
+};
+
+const SheetCreationRender = ({ showHeader }: { showHeader: boolean }) => {
+ const [options, setOptions] = useState(PROFILES);
+ const [value, setValue] = useState<Profile[]>([PROFILES[0]]);
+ const [isPending, setIsPending] = useState(false);
+ const [isDirty, setIsDirty] = useState(false);
+ const [parentSubmits, setParentSubmits] = useState(0);
+ const cancelRef = useRef(() => {});
+ const { requestDiscard, confirmDiscard, isDiscardDialogOpen, setIsDiscardDialogOpen } =
+ useDiscardChangesGuard({
+ isDirty,
+ onDiscard: () => {
+ setIsDirty(false);
+ cancelRef.current();
+ }
+ });
+ const requestCancel = (cancel: () => void) => {
+ cancelRef.current = cancel;
+ requestDiscard();
+ };
+
+ return (
+ <Dialog>
+ <DialogTrigger asChild>
+ <Button variant="project">Attach Profiles</Button>
+ </DialogTrigger>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Attach Certificate Profiles</DialogTitle>
+ <DialogDescription>
+ Creation selects a profile without saving the attachment.
+ </DialogDescription>
+ </DialogHeader>
+ <form
+ className="flex min-h-0 flex-1 flex-col gap-6"
+ onSubmit={(event) => {
+ event.preventDefault();
+ setParentSubmits((count) => count + 1);
+ }}
+ >
+ <DialogBody>
+ <Field>
+ <FieldLabel htmlFor="attach-profiles">Certificate Profiles</FieldLabel>
+ <Combobox
+ id="attach-profiles"
+ multiple
+ options={options}
+ value={value}
+ onValueChange={setValue}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ creation={{
+ mode: "sheet",
+ size: "workspace",
+ ...(showHeader
+ ? {
+ title: "Create Certificate Profile",
+ description: "Configure a profile before attaching it to the application."
+ }
+ : { showHeader: false }),
+ emptyLabel: "Create New Profile",
+ isPending,
+ onDismiss: requestCancel,
+ renderForm: (props) => (
+ <>
+ <ProfileForm
+ {...props}
+ cancel={() => requestCancel(props.cancel)}
+ showHeader={showHeader}
+ isPending={isPending}
+ onPendingChange={setIsPending}
+ onDirtyChange={setIsDirty}
+ onCreated={(profile) => {
+ setOptions((current) => [...current, profile]);
+ setValue((current) => [...current, profile]);
+ }}
+ />
+ <DiscardChangesAlertDialog
+ open={isDiscardDialogOpen}
+ onOpenChange={setIsDiscardDialogOpen}
+ onDiscard={confirmDiscard}
+ title="Discard Profile Setup?"
+ description="Your profile configuration will be lost."
+ />
+ </>
+ )
+ }}
+ />
+ </Field>
+ <p className="mt-2 text-xs text-muted">Attachment submits: {parentSubmits}</p>
+ </DialogBody>
+ <DialogFooter>
+ <Button type="submit" variant="project">
+ Attach
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+};
+
+const meta = {
+ title: "Generic/Combobox/Creation",
+ component: Combobox,
+ parameters: { layout: "centered" },
+ tags: ["autodocs"]
+} satisfies Meta<typeof Combobox>;
+
+export default meta;
+type Story = StoryObj;
+
+export const SheetCreation: Story = {
+ render: () => <SheetCreationRender showHeader />
+};
+
+export const FormOwnedHeader: Story = {
+ parameters: {
+ docs: {
+ description: {
+ story:
+ "Use sheet creation for multi-step forms. With showHeader=false, renderForm provides SheetHeader, SheetTitle, and SheetDescription but no Sheet root or SheetContent. The same caller-owned pending state locks the form and shell; Finish simulated save represents the persistence response."
+ }
+ }
+ },
+ render: () => <SheetCreationRender showHeader={false} />
+};
+
+const DialogCreationRender = () => {
+ const [options, setOptions] = useState(PROFILES);
+ const [value, setValue] = useState<Profile | null>(null);
+
+ return (
+ <div className="w-80">
+ <Field>
+ <FieldLabel htmlFor="dialog-profile">Certificate Profile</FieldLabel>
+ <Combobox
+ id="dialog-profile"
+ options={options}
+ value={value}
+ onValueChange={setValue}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ creation={{
+ mode: "dialog",
+ title: "Create Profile",
+ description: "Name the profile before selecting it.",
+ renderForm: ({ initialInput, complete, cancel }) => (
+ <form
+ className="flex min-h-0 flex-1 flex-col gap-6"
+ onSubmit={(event) => {
+ event.preventDefault();
+ const name = String(new FormData(event.currentTarget).get("name")).trim();
+ if (!name) return;
+ const profile = { id: name, name };
+ setOptions((current) => [...current, profile]);
+ setValue(profile);
+ complete();
+ }}
+ >
+ <DialogBody>
+ <Field>
+ <FieldLabel htmlFor="dialog-profile-name">Profile Name</FieldLabel>
+ <Input
+ id="dialog-profile-name"
+ name="name"
+ defaultValue={initialInput}
+ required
+ />
+ </Field>
+ </DialogBody>
+ <DialogFooter>
+ <Button variant="ghost" onClick={cancel}>
+ Cancel
+ </Button>
+ <Button type="submit" variant="project">
+ Create Profile
+ </Button>
+ </DialogFooter>
+ </form>
+ )
+ }}
+ />
+ </Field>
+ </div>
+ );
+};
+
+export const DialogCreation: Story = {
+ render: () => <DialogCreationRender />
+};
+
+const ActionCreationRender = () => {
+ const [primary, setPrimary] = useState<Profile | null>(ISSUERS[0]);
+ const [additional, setAdditional] = useState<Profile[]>([ISSUERS[0]]);
+ const [isDisabled, setIsDisabled] = useState(false);
+ const [wizard, setWizard] = useState<{ field: string; initialInput: string } | null>(null);
+
+ return (
+ <Sheet>
+ <SheetTrigger asChild>
+ <Button variant="project">Configure Issuer</Button>
+ </SheetTrigger>
+ <SheetContent size="wide">
+ <SheetHeader>
+ <SheetTitle>Configure Issuer</SheetTitle>
+ <SheetDescription>
+ Create a policy in this sheet without opening another overlay.
+ </SheetDescription>
+ </SheetHeader>
+ <div className="min-h-0 flex-1 overflow-y-auto p-4">
+ {wizard ? (
+ <div className="flex flex-col gap-4">
+ <h2 className="font-alliance text-lg">New Policy for {wizard.field}</h2>
+ <p>Initial query: {wizard.initialInput || "(empty)"}</p>
+ <p>Primary selection: {primary?.name}</p>
+ <p>Additional selections: {additional.map((option) => option.name).join(", ")}</p>
+ <Button variant="outline" onClick={() => setWizard(null)}>
+ Back to Issuer
+ </Button>
+ </div>
+ ) : (
+ <div className="flex flex-col gap-6">
+ <Field>
+ <FieldLabel htmlFor="primary-policy">Primary Policy</FieldLabel>
+ <Combobox
+ id="primary-policy"
+ options={ISSUERS}
+ value={primary}
+ onValueChange={setPrimary}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ creation={{
+ mode: "action",
+ emptyLabel: "Create New Policy",
+ formatLabel: () => "Create New Policy",
+ isDisabled,
+ onAction: (initialInput) => setWizard({ field: "Primary", initialInput })
+ }}
+ />
+ </Field>
+ <Field>
+ <FieldLabel htmlFor="additional-policies">Additional Policies</FieldLabel>
+ <Combobox
+ id="additional-policies"
+ multiple
+ options={ISSUERS}
+ value={additional}
+ onValueChange={setAdditional}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ creation={{
+ mode: "action",
+ emptyLabel: "Create New Policy",
+ formatLabel: () => "Create New Policy",
+ isDisabled,
+ onAction: (initialInput) => setWizard({ field: "Additional", initialInput })
+ }}
+ />
+ </Field>
+ <Button variant="outline" onClick={() => setIsDisabled(!isDisabled)}>
+ {isDisabled ? "Enable Creation" : "Disable Creation"}
+ </Button>
+ </div>
+ )}
+ </div>
+ <SheetFooter>
+ <SheetClose asChild>
+ <Button variant="ghost">Cancel</Button>
+ </SheetClose>
+ </SheetFooter>
+ </SheetContent>
+ </Sheet>
+ );
+};
+
+export const ActionCreation: Story = {
+ render: () => <ActionCreationRender />
+};
diff --git a/frontend/src/components/v3/generic/Combobox/Combobox.tsx b/frontend/src/components/v3/generic/Combobox/Combobox.tsx
index 932da8c6c1..27fe988558 100644
--- a/frontend/src/components/v3/generic/Combobox/Combobox.tsx
+++ b/frontend/src/components/v3/generic/Combobox/Combobox.tsx
@@ -6,6 +6,7 @@ import { cn } from "../../utils";
import { useIsInsideOverlayLayer, useOverlayPopupRegistration } from "../../utils/overlay-layer";
import { useScrollEdges } from "../../utils/useScrollEdges";
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "../Dialog";
+import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "../Sheet";
import { getComboboxInputAriaLabel } from "./combobox-accessibility";
import {
COMBOBOX_CHIP_CLASS,
@@ -45,26 +46,59 @@ type ComboboxInlineCreationConfig<TOption> = ComboboxCreationBaseConfig<TOption>
isPending?: boolean;
};
-type ComboboxDialogCreationRenderProps = {
+type ComboboxFormCreationRenderProps = {
initialInput: string;
complete: () => void;
cancel: () => void;
};
-type ComboboxDialogCreationConfig<TOption> = ComboboxCreationBaseConfig<TOption> & {
- mode: "dialog";
- title: React.ReactNode;
- description: React.ReactNode;
- renderForm: (props: ComboboxDialogCreationRenderProps) => React.ReactNode;
- /** Prevent dismissing the dialog while caller-owned persistence is pending. */
+type ComboboxDialogCreationRenderProps = ComboboxFormCreationRenderProps;
+
+type ComboboxFormCreationConfig<TOption> = ComboboxCreationBaseConfig<TOption> & {
+ renderForm: (props: ComboboxFormCreationRenderProps) => React.ReactNode;
+ /** Prevent dismissing the creation overlay while caller-owned persistence is pending. */
isPending?: boolean;
/** Intercepts Escape, outside press, and the close button (e.g. to confirm discarding changes); call `cancel` to close. */
onDismiss?: (cancel: () => void) => void;
};
+type ComboboxDialogCreationConfig<TOption> = ComboboxFormCreationConfig<TOption> & {
+ mode: "dialog";
+ title: React.ReactNode;
+ description: React.ReactNode;
+};
+
+type ComboboxSheetCreationConfig<TOption> = ComboboxFormCreationConfig<TOption> & {
+ mode: "sheet";
+ size?: React.ComponentProps<typeof SheetContent>["size"];
+} & (
+ | {
+ showHeader?: true;
+ title: React.ReactNode;
+ description: React.ReactNode;
+ }
+ | {
+ /** The form must provide SheetHeader, SheetTitle, and SheetDescription. */
+ showHeader: false;
+ title?: never;
+ description?: never;
+ }
+ );
+
+type ComboboxActionCreationConfig<TOption> = Pick<
+ ComboboxCreationBaseConfig<TOption>,
+ "emptyLabel" | "formatLabel" | "isDisabled"
+> & {
+ mode: "action";
+ /** Closes the picker and starts a caller-owned workflow without persisting or selecting an option. */
+ onAction: (inputValue: string) => void;
+};
+
type ComboboxCreationConfig<TOption> =
| ComboboxInlineCreationConfig<TOption>
- | ComboboxDialogCreationConfig<TOption>;
+ | ComboboxDialogCreationConfig<TOption>
+ | ComboboxSheetCreationConfig<TOption>
+ | ComboboxActionCreationConfig<TOption>;
type ComboboxSharedProps<TOption> = {
options?: readonly TOption[];
@@ -98,8 +132,9 @@ type ComboboxSharedProps<TOption> = {
includeMissingSelectedOptions?: boolean;
/**
* Adds a fixed Create footer option. Inline mode persists directly from the query;
- * dialog mode delegates metadata, validation, persistence, and controlled
+ * dialog and sheet modes delegate metadata, validation, persistence, and controlled
* option/selection updates to the caller's form.
+ * Action mode starts a caller-owned workflow without an additional overlay.
*/
creation?: ComboboxCreationConfig<TOption>;
};
@@ -297,11 +332,12 @@ type ComboboxGroup<TOption> = {
const isInlineCreationConfig = <TOption,>(
creation?: ComboboxCreationConfig<TOption>
): creation is ComboboxInlineCreationConfig<TOption> =>
- Boolean(creation && creation.mode !== "dialog");
+ Boolean(creation && (creation.mode === undefined || creation.mode === "inline"));
-const isDialogCreationConfig = <TOption,>(
+const isFormCreationConfig = <TOption,>(
creation?: ComboboxCreationConfig<TOption>
-): creation is ComboboxDialogCreationConfig<TOption> => creation?.mode === "dialog";
+): creation is ComboboxDialogCreationConfig<TOption> | ComboboxSheetCreationConfig<TOption> =>
+ creation?.mode === "dialog" || creation?.mode === "sheet";
const usePrimitiveComboboxItems = <TOption,>(
items: readonly TOption[],
@@ -412,7 +448,12 @@ const ComboboxList = <TOption,>({
key={`create:${item.inputValue}`}
data-slot="combobox-create-item"
value={item}
- disabled={!canCreate || creation?.isDisabled || creation?.isPending || isCreationPending}
+ disabled={
+ !canCreate ||
+ creation?.isDisabled ||
+ (creation?.mode !== "action" && creation?.isPending) ||
+ isCreationPending
+ }
className={cn(
COMBOBOX_ROW_CLASS,
"w-full px-2 data-[disabled]:cursor-not-allowed data-[disabled]:opacity-65 data-[highlighted]:bg-foreground/5 data-[highlighted]:text-foreground"
@@ -706,8 +747,8 @@ const useComboboxCreation = <TOption,>({
};
};
-type ComboboxDialogCreationState<TOption> = {
- creation?: ComboboxDialogCreationConfig<TOption>;
+type ComboboxFormCreationState<TOption> = {
+ creation?: ComboboxDialogCreationConfig<TOption> | ComboboxSheetCreationConfig<TOption>;
initialInput: string;
isOpen: boolean;
open: (inputValue: string) => void;
@@ -717,9 +758,9 @@ type ComboboxDialogCreationState<TOption> = {
onCloseAutoFocus: (event: Event) => void;
};
-type ComboboxCreationDialogProps<TOption> = Omit<ComboboxDialogCreationState<TOption>, "open">;
+type ComboboxCreationOverlayProps<TOption> = Omit<ComboboxFormCreationState<TOption>, "open">;
-const useComboboxDialogCreation = <TOption,>({
+const useComboboxFormCreation = <TOption,>({
creation,
onComplete,
onClosed
@@ -727,20 +768,20 @@ const useComboboxDialogCreation = <TOption,>({
creation?: ComboboxCreationConfig<TOption>;
onComplete: (inputValue: string) => void;
onClosed: (outcome: "complete" | "cancel") => void;
-}): ComboboxDialogCreationState<TOption> => {
- const dialogCreation = isDialogCreationConfig(creation) ? creation : undefined;
+}): ComboboxFormCreationState<TOption> => {
+ const formCreation = isFormCreationConfig(creation) ? creation : undefined;
const [initialInput, setInitialInput] = React.useState("");
const [isOpen, setIsOpen] = React.useState(false);
const outcomeRef = React.useRef<"complete" | "cancel" | null>(null);
const open = React.useCallback(
(inputValue: string) => {
- if (!dialogCreation || dialogCreation.isDisabled || dialogCreation.isPending) return;
+ if (!formCreation || formCreation.isDisabled || formCreation.isPending) return;
outcomeRef.current = null;
setInitialInput(inputValue);
setIsOpen(true);
},
- [dialogCreation]
+ [formCreation]
);
const complete = React.useCallback(() => {
@@ -750,18 +791,18 @@ const useComboboxDialogCreation = <TOption,>({
}, [initialInput, onComplete]);
const cancel = React.useCallback(() => {
- if (dialogCreation?.isPending) return;
+ if (formCreation?.isPending) return;
outcomeRef.current = "cancel";
setIsOpen(false);
- }, [dialogCreation?.isPending]);
+ }, [formCreation?.isPending]);
const onOpenChange = React.useCallback(
(nextOpen: boolean) => {
if (nextOpen) return;
- if (dialogCreation?.onDismiss) dialogCreation.onDismiss(cancel);
+ if (formCreation?.onDismiss) formCreation.onDismiss(cancel);
else cancel();
},
- [cancel, dialogCreation]
+ [cancel, formCreation]
);
const onCloseAutoFocus = React.useCallback(
@@ -775,7 +816,7 @@ const useComboboxDialogCreation = <TOption,>({
);
return {
- creation: dialogCreation,
+ creation: formCreation,
initialInput,
isOpen,
open,
@@ -786,7 +827,7 @@ const useComboboxDialogCreation = <TOption,>({
};
};
-const ComboboxCreationDialog = <TOption,>({
+const ComboboxCreationOverlay = <TOption,>({
creation,
initialInput,
isOpen,
@@ -794,13 +835,34 @@ const ComboboxCreationDialog = <TOption,>({
cancel,
onOpenChange,
onCloseAutoFocus
-}: ComboboxCreationDialogProps<TOption>) => {
+}: ComboboxCreationOverlayProps<TOption>) => {
if (!creation) return null;
const preventPendingDismissal = (event: Event) => {
if (creation.isPending) event.preventDefault();
};
+ if (creation.mode === "sheet") {
+ return (
+ <Sheet open={isOpen} onOpenChange={onOpenChange}>
+ <SheetContent
+ size={creation.size}
+ isPending={creation.isPending}
+ onCloseAutoFocus={onCloseAutoFocus}
+ onSubmit={(event) => event.stopPropagation()}
+ >
+ {creation.showHeader !== false && (
+ <SheetHeader>
+ <SheetTitle>{creation.title}</SheetTitle>
+ <SheetDescription>{creation.description}</SheetDescription>
+ </SheetHeader>
+ )}
+ {creation.renderForm({ initialInput, complete, cancel })}
+ </SheetContent>
+ </Sheet>
+ );
+ }
+
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
<DialogContent
@@ -873,7 +935,7 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
const [search, setSearch] = React.useState("");
const searchRef = React.useRef(search);
searchRef.current = search;
- const isDialogCreationActiveRef = React.useRef(false);
+ const isFormCreationActiveRef = React.useRef(false);
const [isEditing, setIsEditingState] = React.useState(false);
const isEditingRef = React.useRef(isEditing);
isEditingRef.current = isEditing;
@@ -930,17 +992,20 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
onInputValueChange?.(nextSearch);
};
// Dialog creation collects its own fields, so its create row also opens from an empty query.
+ const creationQuery = isEditing ? search.trim() : "";
const creationInput =
- (creation && isEditing
- ? getComboboxCreationInput({
- inputValue: search,
- options,
- selectedOptions,
- getOptionLabel,
- isDuplicate: creation.isDuplicate,
- isValid: creation.isValid
- })
- : null) ?? (isDialogCreationConfig(creation) && !(isEditing && search.trim()) ? "" : null);
+ creation?.mode === "action"
+ ? creationQuery
+ : ((creation && isEditing
+ ? getComboboxCreationInput({
+ inputValue: search,
+ options,
+ selectedOptions,
+ getOptionLabel,
+ isDuplicate: creation.isDuplicate,
+ isValid: creation.isValid
+ })
+ : null) ?? (isFormCreationConfig(creation) && !(isEditing && search.trim()) ? "" : null));
const handleCreationSuccess = React.useCallback(
(inputValue: string) => {
if (searchRef.current.trim() !== inputValue) return;
@@ -952,17 +1017,17 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
},
[onInputValueChange, onSearchChange, setIsEditing]
);
- const handleCreationDialogClosed = React.useCallback((outcome: "complete" | "cancel") => {
+ const handleCreationOverlayClosed = React.useCallback((outcome: "complete" | "cancel") => {
if (outcome === "cancel") setOpen(true);
window.requestAnimationFrame(() => {
inputRef.current?.focus();
- isDialogCreationActiveRef.current = false;
+ isFormCreationActiveRef.current = false;
});
}, []);
- const dialogCreation = useComboboxDialogCreation({
+ const formCreation = useComboboxFormCreation({
creation,
onComplete: handleCreationSuccess,
- onClosed: handleCreationDialogClosed
+ onClosed: handleCreationOverlayClosed
});
const {
clearError: clearCreationError,
@@ -984,7 +1049,7 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
window.requestAnimationFrame(() => inputRef.current?.focus());
};
const creationItem: ComboboxCreateItem | null = creation
- ? { type: "create", inputValue: pendingInputValue ?? (isEditing ? search.trim() : "") }
+ ? { type: "create", inputValue: pendingInputValue ?? creationQuery }
: null;
const primitiveItems = React.useMemo(() => {
if (!creationItem) return rootItems;
@@ -1017,10 +1082,14 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
if (nextValue.type === "create") {
eventDetails.cancel();
if (creationInput === null || nextValue.inputValue !== creationInput) return;
- if (dialogCreation.creation) {
- isDialogCreationActiveRef.current = true;
+ if (creation?.mode === "action") {
+ if (creation.isDisabled) return;
setOpen(false);
- dialogCreation.open(creationInput);
+ creation.onAction(creationInput);
+ } else if (formCreation.creation) {
+ isFormCreationActiveRef.current = true;
+ setOpen(false);
+ formCreation.open(creationInput);
} else {
createOption(creationInput);
}
@@ -1042,14 +1111,14 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
setOpen(true);
return;
}
- const isOpeningCreationDialog =
+ const isOpeningCreationOverlay =
!nextOpen &&
eventDetails.reason === "item-press" &&
- isDialogCreationConfig(creation) &&
- (isDialogCreationActiveRef.current || isComboboxCreateItemEvent(eventDetails.event));
+ isFormCreationConfig(creation) &&
+ (isFormCreationActiveRef.current || isComboboxCreateItemEvent(eventDetails.event));
if (!nextOpen) markPopupDismissEvent(eventDetails.event);
setOpen(nextOpen);
- if (!nextOpen && !isCreationActive() && !isOpeningCreationDialog) {
+ if (!nextOpen && !isCreationActive() && !isOpeningCreationOverlay) {
highlightedOptionValueRef.current = null;
setIsEditing(false);
updateSearch("");
@@ -1065,7 +1134,7 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
if (eventDetails.reason === "input-change" || eventDetails.reason === "input-clear") {
if (
eventDetails.reason === "input-clear" &&
- (isCreationActive() || isDialogCreationActiveRef.current)
+ (isCreationActive() || isFormCreationActiveRef.current)
)
return;
setIsEditing(eventDetails.reason === "input-change");
@@ -1209,7 +1278,7 @@ const SingleCombobox = <TOption,>(props: ComboboxSingleProps<TOption>) => {
onClear={handleClear}
/>
</div>
- <ComboboxCreationDialog {...dialogCreation} />
+ <ComboboxCreationOverlay {...formCreation} />
</>
);
};
@@ -1270,7 +1339,7 @@ const MultipleCombobox = <TOption,>({
const [search, setSearch] = React.useState("");
const searchRef = React.useRef(search);
searchRef.current = search;
- const isDialogCreationActiveRef = React.useRef(false);
+ const isFormCreationActiveRef = React.useRef(false);
const selectedOptions = React.useMemo(() => [...value], [value]);
// A caller-owned search returns one already-filtered page after a debounce and a round trip.
// The local matcher must not filter that page again, a selection missing from it is not a
@@ -1329,16 +1398,18 @@ const MultipleCombobox = <TOption,>({
selectAllOptions.every((option) => selectedValues.has(getOptionValue(option)));
// Dialog creation collects its own fields, so its create row also opens from an empty query.
const creationInput =
- (creation
- ? getComboboxCreationInput({
- inputValue: search,
- options,
- selectedOptions,
- getOptionLabel,
- isDuplicate: creation.isDuplicate,
- isValid: creation.isValid
- })
- : null) ?? (isDialogCreationConfig(creation) && !search.trim() ? "" : null);
+ creation?.mode === "action"
+ ? search.trim()
+ : ((creation
+ ? getComboboxCreationInput({
+ inputValue: search,
+ options,
+ selectedOptions,
+ getOptionLabel,
+ isDuplicate: creation.isDuplicate,
+ isValid: creation.isValid
+ })
+ : null) ?? (isFormCreationConfig(creation) && !search.trim() ? "" : null));
const handleCreationSuccess = React.useCallback(
(inputValue: string) => {
if (searchRef.current.trim() !== inputValue) return;
@@ -1349,20 +1420,20 @@ const MultipleCombobox = <TOption,>({
},
[onInputValueChange, onSearchChange]
);
- const handleCreationDialogClosed = React.useCallback((outcome: "complete" | "cancel") => {
+ const handleCreationOverlayClosed = React.useCallback((outcome: "complete" | "cancel") => {
if (outcome === "cancel") {
openRef.current = true;
setOpen(true);
}
window.requestAnimationFrame(() => {
inputRef.current?.focus();
- isDialogCreationActiveRef.current = false;
+ isFormCreationActiveRef.current = false;
});
}, []);
- const dialogCreation = useComboboxDialogCreation({
+ const formCreation = useComboboxFormCreation({
creation,
onComplete: handleCreationSuccess,
- onClosed: handleCreationDialogClosed
+ onClosed: handleCreationOverlayClosed
});
const {
clearError: clearCreationError,
@@ -1428,11 +1499,16 @@ const MultipleCombobox = <TOption,>({
if (createItem) {
eventDetails.cancel();
if (creationInput === null || createItem.inputValue !== creationInput) return;
- if (dialogCreation.creation) {
- isDialogCreationActiveRef.current = true;
+ if (creation?.mode === "action") {
+ if (creation.isDisabled) return;
+ openRef.current = false;
+ setOpen(false);
+ creation.onAction(creationInput);
+ } else if (formCreation.creation) {
+ isFormCreationActiveRef.current = true;
openRef.current = false;
setOpen(false);
- dialogCreation.open(creationInput);
+ formCreation.open(creationInput);
} else {
createOption(creationInput);
}
@@ -1470,15 +1546,15 @@ const MultipleCombobox = <TOption,>({
setOpen(true);
return;
}
- const isOpeningCreationDialog =
+ const isOpeningCreationOverlay =
!nextOpen &&
eventDetails.reason === "item-press" &&
- isDialogCreationConfig(creation) &&
- (isDialogCreationActiveRef.current || isComboboxCreateItemEvent(eventDetails.event));
+ isFormCreationConfig(creation) &&
+ (isFormCreationActiveRef.current || isComboboxCreateItemEvent(eventDetails.event));
if (!nextOpen) markPopupDismissEvent(eventDetails.event);
openRef.current = nextOpen;
setOpen(nextOpen);
- if (!nextOpen && !isCreationActive() && !isOpeningCreationDialog) {
+ if (!nextOpen && !isCreationActive() && !isOpeningCreationOverlay) {
updateSearch("");
clearCreationError();
}
@@ -1487,7 +1563,7 @@ const MultipleCombobox = <TOption,>({
onInputValueChange={(nextValue, eventDetails) => {
if (
eventDetails.reason === "input-clear" &&
- (isCreationActive() || isDialogCreationActiveRef.current)
+ (isCreationActive() || isFormCreationActiveRef.current)
)
return;
if (eventDetails.reason === "input-change" || eventDetails.reason === "input-clear") {
@@ -1631,7 +1707,7 @@ const MultipleCombobox = <TOption,>({
onClear={handleClear}
/>
</div>
- <ComboboxCreationDialog {...dialogCreation} />
+ <ComboboxCreationOverlay {...formCreation} />
</>
);
};
@@ -1666,12 +1742,15 @@ function Combobox<TOption>(props: ComboboxProps<TOption>) {
export {
Combobox,
+ type ComboboxActionCreationConfig,
type ComboboxCreationConfig,
type ComboboxDialogCreationConfig,
type ComboboxDialogCreationRenderProps,
+ type ComboboxFormCreationRenderProps,
type ComboboxInlineCreationConfig,
type ComboboxMultipleProps,
type ComboboxProps,
type ComboboxRenderOptionState,
+ type ComboboxSheetCreationConfig,
type ComboboxSingleProps
};
diff --git a/frontend/src/components/v3/generic/Combobox/index.ts b/frontend/src/components/v3/generic/Combobox/index.ts
index a9afb2eb45..6a37af7b6a 100644
--- a/frontend/src/components/v3/generic/Combobox/index.ts
+++ b/frontend/src/components/v3/generic/Combobox/index.ts
@@ -1,11 +1,14 @@
export {
Combobox,
+ type ComboboxActionCreationConfig,
type ComboboxCreationConfig,
type ComboboxDialogCreationConfig,
type ComboboxDialogCreationRenderProps,
+ type ComboboxFormCreationRenderProps,
type ComboboxInlineCreationConfig,
type ComboboxMultipleProps,
type ComboboxProps,
type ComboboxRenderOptionState,
+ type ComboboxSheetCreationConfig,
type ComboboxSingleProps
} from "./Combobox";