@chakra-ui/alert-dialog
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-next.3 • Public • Published

@chakra-ui/alert-dialog

AlertDialog component is used interrupt the user with a mandatory confirmation or action.

Installation

yarn add @chakra-ui/alert-dialog

# or

npm i @chakra-ui/alert-dialog

Import components

import {
  AlertDialog,
  AlertDialogBody,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogContent,
  AlertDialogOverlay,
} from "@chakra-ui/core"

Basic usage

Usage

AlertDialog requires that you provide the leastDestructiveRef prop.

Based on WAI-ARIA specifications, focus should be placed on the least destructive element when the dialog opens, to prevent users from accidentally confirming the destructive action.

function AlertDialogExample() {
  const [isOpen, setIsOpen] = React.useState()
  const onClose = () => setIsOpen(false)
  const cancelRef = React.useRef()

  return (
    <>
      <Button colorScheme="red" onClick={() => setIsOpen(true)}>
        Delete Customer
      </Button>

      <AlertDialog
        isOpen={isOpen}
        leastDestructiveRef={cancelRef}
        onClose={onClose}
      >
        <AlertDialogOverlay>
          <AlertDialogContent>
            <AlertDialogHeader fontSize="lg" fontWeight="bold">
              Delete Customer
            </AlertDialogHeader>

            <AlertDialogBody>
              Are you sure? You can't undo this action afterwards.
            </AlertDialogBody>

            <AlertDialogFooter>
              <Button ref={cancelRef} onClick={onClose}>
                Cancel
              </Button>
              <Button colorScheme="red" onClick={onClose} ml={3}>
                Delete
              </Button>
            </AlertDialogFooter>
          </AlertDialogContent>
        </AlertDialogOverlay>
      </AlertDialog>
    </>
  )
}

Package Sidebar

Install

npm i @chakra-ui/alert-dialog

Weekly Downloads

343

Version

1.0.0-next.3

License

MIT

Unpacked Size

42.9 kB

Total Files

18

Last publish

Collaborators

  • segunadebayo
  • _codebender828