For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/en/components/confirm.md.
  • English
  • Confirm

    Ask for confirmation before an important action. Call the API and await the user's choice.

    Configure the entry once

    Wrap the application in ConfigProvider and call useConfirm() in a child component. Each confirmation inherits the caller's theme and language without managing open state.

    import { ConfigProvider } from '@ifhover/leaf-ui';
    
    export function Root() {
      return <ConfigProvider><App /></ConfigProvider>;
    }

    Async confirmation

    basic.tsx
    import { Button, Space, useConfirm, useMessage } from '@ifhover/leaf-ui';
    
    export function ConfirmBasic() {
      const { confirm } = useConfirm();
      const { message } = useMessage();
      return (
        <Space direction="vertical" align="center">
          <Button
            danger
            variant="outline"
            onClick={async () => {
              const accepted = await confirm({
                title: 'Delete project',
                children: 'This cannot be undone. Continue?',
                type: 'danger',
                onConfirm: () => new Promise((resolve) => setTimeout(resolve, 900)),
              });
              if (accepted) message.success('Project deleted');
            }}
          >
            Delete project
          </Button>
        </Space>
      );
    }
    

    useConfirm API

    The returned object is ConfirmApi.

    PropTypeDefaultDescription
    confirm(options: ConfirmOptions) => Promise<boolean>—Resolves true on confirmation, false on cancellation or caller unmount.

    ConfirmOptions

    PropertyTypeDefaultDescription
    initialFocusRefObject<HTMLElement | null> | (() => HTMLElement | null)—Initial focus target.
    returnFocusboolean | RefObject<HTMLElement | null> | (() => HTMLElement | null)—Return focus after closing; set a target or disable with false.
    titleReactNode—Confirmation heading.
    childrenReactNode—A short explanation of the action's consequences.
    iconReactNode—Semantic icon beside the explanation; null hides the icon.
    type'default' | 'danger' | 'success' | 'warning' | 'info''default'Semantic icon and color; only danger changes the confirm button color.
    showCancelbooleanfalse for success; otherwise trueShow the cancel button.
    confirmTextReactNodeLocale defaultConfirm button label.
    cancelTextReactNodeLocale defaultCancel button label.
    confirmButtonPropsButtonProps—Confirm button props.
    cancelButtonPropsButtonProps—Cancel button props.
    onConfirm() => void | Promise<void>—Close after success; keep the dialog open and show the error on rejection.
    onCancel() => void—Called on cancellation.
    widthnumber | string420Dialog width, in pixels for numbers.
    closablebooleanfalseShow a close button in the corner.
    maskClosablebooleanfalseCancel when the backdrop is clicked.
    keyboardbooleantrueCancel when Escape is pressed.
    classNamestring—Dialog class name.
    styleCSSProperties—Dialog styles.

    ConfirmProvider API

    Use ConfirmProvider at the entry when ConfigProvider is absent. An explicit provider can also create an independent queue for a region.

    import { ConfirmProvider } from '@ifhover/leaf-ui';
    
    export function Root() {
      return <ConfirmProvider><App /></ConfirmProvider>;
    }
    PropertyTypeDefaultDescription
    childrenReactNode—Components sharing this confirmation queue.

    ConfirmApi

    PropertyTypeDefaultDescription
    confirm(options: ConfirmOptions) => Promise<boolean>—Required. Request confirmation and await the choice.

    Types

    Import these types when composing options.

    import type { ConfirmOptions, ConfirmApi, ConfirmProviderProps } from '@ifhover/leaf-ui';

    Usage

    useConfirm() returns { confirm }. Requests sharing an entry appear in sequence, after the previous dialog finishes closing. Async confirmation shows loading and prevents duplicate actions; rejected actions keep the dialog open with an error and can be retried.

    The default type has no status icon. Info, warning, success and danger show a bare semantic icon beside the content; danger uses a red exclamation mark. Success hides the cancel button unless showCancel is set.

    Confirm is an API-only prompt for brief decisions. Use Modal for forms, multiple steps or complex content.