View as Markdown

API reference: @salmonui/overlays/dialog

AlertDialogPropsinterface

import type { AlertDialogProps } from '@salmonui/overlays/dialog';
interface AlertDialogProps extends Omit<DialogProps, 'title' | 'dismissible' | 'trigger' | 'children' | 'localeText'> {
    readonly title: ReactNode;
    readonly description?: ReactNode;
    readonly children?: ReactNode;
    readonly trigger?: ReactNode;
    readonly confirmLabel?: ReactNode;
    readonly cancelLabel?: ReactNode;
    readonly confirmIcon?: ReactNode;
    readonly cancelIcon?: ReactNode;
    readonly tone?: 'primary' | 'danger' | undefined;
    readonly onConfirm?: ((formData: FormData | undefined) => unknown) | undefined;
    readonly onCancel?: (() => void) | undefined;
    readonly dismissible?: boolean | undefined;
    readonly localeText?: AlertDialogLocaleText | undefined;
}
AlertDialogProps members (45, 32 inherited)
NameSignatureDescription
titlereadonly title: ReactNode;
descriptionoptionalreadonly description?: ReactNode;
childrenoptionalreadonly children?: ReactNode;

Form fields (a prompt): the body and actions become a <form>; submitting it (Enter or the confirm button) calls onConfirm(formData).

triggeroptionalreadonly trigger?: ReactNode;
confirmLabeloptionalreadonly confirmLabel?: ReactNode;
cancelLabeloptionalreadonly cancelLabel?: ReactNode;

Without a cancel label (and without localeText.cancel plus onCancel) the dialog is an alert with one action.

confirmIconoptionalreadonly confirmIcon?: ReactNode;
cancelIconoptionalreadonly cancelIcon?: ReactNode;
toneoptionalreadonly tone?: 'primary' | 'danger' | undefined;

'danger' styles the confirm button for destructive actions.

onConfirmoptionalreadonly onConfirm?: ((formData: FormData | undefined) => unknown) | undefined;

May return a promise: the confirm button shows its loading state and the dialog stays open until it settles. While pending, Cancel is disabled and Escape and the close button are ignored. A rejection keeps the dialog open and shows the reason's Error message (else localeText.error) in a role="alert" region above the actions; confirming again clears it.

onCanceloptionalreadonly onCancel?: (() => void) | undefined;
dismissibleoptionalreadonly dismissible?: boolean | undefined;

Escape cancels. Default true.

localeTextoptionalreadonly localeText?: AlertDialogLocaleText | undefined;
openoptionalinheritedopen?: boolean;
defaultOpenoptionalinheriteddefaultOpen?: boolean;
onOpenChangeoptionalinheritedonOpenChange?: ((open: boolean, event: DialogOpenChangeEvent) => void);
onAfterOpenoptionalinheritedonAfterOpen?: (() => void);
onAfterCloseoptionalinheritedonAfterClose?: (() => void);
modaloptionalinheritedmodal?: boolean;

showModal() (default) or show() (modeless: no backdrop, no focus containment).

onOverlayPressoptionalinheritedonOverlayPress?: ((event: PointerEvent) => void);

Press on the backdrop of a modal dialog.

closeButtonoptionalinheritedcloseButton?: boolean;

A close button in the corner (label localeText.close). Default false.

initialFocusoptionalinheritedinitialFocus?: false | RefObject<HTMLElement | null>;

Element focused on open (else [data-autofocus], else the first focusable); false keeps the platform default.

returnFocusoptionalinheritedreturnFocus?: boolean;

Return focus to the invoker on close. Default true.

containeroptionalinheritedcontainer?: Element | null;

Modeless only: render the dialog inside this element (positioned in it) instead of in place. Mounted after hydration.

keepMountedoptionalinheritedkeepMounted?: boolean;

Render the closed <dialog> too (content in the server HTML).

placementoptionalinheritedplacement?: "center" | "top";

'center' (default) or 'top'.

positionoptionalinheritedposition?: DialogPosition;
defaultPositionoptionalinheriteddefaultPosition?: DialogPosition;
onPositionChangeoptionalinheritedonPositionChange?: ((position: DialogPosition) => void);
widthoptionalinheritedwidth?: string | number;
heightoptionalinheritedheight?: string | number;
minHeightoptionalinheritedminHeight?: string | number;
fullScreenoptionalinheritedfullScreen?: "mobile" | boolean;

Fill the viewport, or only below the mobile width (640 px).

draggableoptionalinheriteddraggable?: boolean;

Drag by dragHandle (default the title); lazy chunk.

dragHandleoptionalinheriteddragHandle?: string;

CSS selector of the drag handle inside the dialog. Default .salmon-dialog-title.

onMoveStartoptionalinheritedonMoveStart?: (() => void);
onMoveoptionalinheritedonMove?: ((position: DialogPosition) => void);

Per animation frame during a drag; not for React state.

onMoveEndoptionalinheritedonMoveEnd?: ((position: DialogPosition) => void);
resizableoptionalinheritedresizable?: boolean | readonly DialogResizeEdge[];

Resize from ['bottomEnd'] (true) or the given edges; lazy chunk.

onResizeStartoptionalinheritedonResizeStart?: (() => void);
onResizeoptionalinheritedonResize?: ((size: DialogSize) => void);
onResizeEndoptionalinheritedonResizeEnd?: ((size: DialogSize) => void);
classNamesoptionalinheritedclassNames?: Partial<Record<"closeButton", string>>;
stylesoptionalinheritedstyles?: Partial<Record<"closeButton", CSSProperties>>;
refoptionalinheritedref?: Ref<HTMLDialogElement>;

The <dialog> element.