Chakra UI Overlay Alert Dialog
Last Updated :
24 Apr, 2025
Chakra UI Overlay Alert Dialog component helps you bring user attention to critical actions or information. It creates a modal overlay, preventing interaction with the main interface until a decision is made. In the following situations we generally uses the Chakra UI Overlay Alert Dialog:
- Confirmation prompts: Ensure users understand the consequences of actions before they commit.
- Error messages: Clearly communicate issues requiring user attention.
- Success notifications: Celebrate achievements and provide feedback in a dedicated space.
With its customizable design and accessibility features, Chakra UI Overlay Alert Dialog empowers you to deliver clear, impactful messages and guide users towards informed decisions within your application.
Prerequisites:
Approach:
We created a basic "Delete" function to implement the delete functionality in websites and use Chakra UI Alert Dialog Component from the Chakra UI Library and implements the Chakra UI Overlay Alert Dialog using React.
Steps to Create the Project:
Step 1: Create a React application using the following command:
npx create-react-app gfg
Step 2: After creating your project folder(i.e. my-app), move to it by using the following command:
cd gfg
Step 3: After creating the React application, Install the required package using the following command:
npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6
Project Structure:
Project StructureThe updated dependencies in package.json will look like this:
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"framer-motion": "^11.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Example: Write down the code in respective files:
JavaScript
// App.js
import React from 'react';
import {
ChakraProvider,
CSSReset, Box, Container
}
from '@chakra-ui/react';
import AlertDialog from './AlertDialog';
function App() {
return (
<ChakraProvider>
<CSSReset />
<Container maxW="container.sm" mt={10}>
<Box>
<AlertDialog />
</Box>
</Container>
</ChakraProvider>
);
}
export default App;
JavaScript
// AlertDialog.js
import React, { useState, useRef } from "react";
import {
Button,
AlertDialog,
AlertDialogBody,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogContent,
AlertDialogOverlay,
} from "@chakra-ui/react";
const DeleteButtonWithConfirmation = () => {
const [isOpen, setIsOpen] = useState(false);
const cancelRef = useRef();
const handleDelete = () => {
// Write functionality according to the
// function requirements
};
const onOpen = () => setIsOpen(true);
const onClose = () => setIsOpen(false);
return (
<>
<Button colorScheme="red" onClick={onOpen}>
Delete
</Button>
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={cancelRef}
onClose={onClose}
>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize="lg" fontWeight="bold">
Delete Item
</AlertDialogHeader>
<AlertDialogBody>
Are you sure you want to delete this item? This
action cannot be undone.
</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose}>
Cancel
</Button>
<Button
colorScheme="red"
onClick={handleDelete}
ml={3}
>
Delete
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
</>
);
};
export default DeleteButtonWithConfirmation;
Steps to run the application:
Step 1: Type the following command in terminal
npm start
Step 2: Open web-browser and type the following URL
http://localhost:3000/
Output:
Output
Similar Reads
Chakra UI Overlay Modal
Chakra UI Overlay Modal is a component used to create modal dialogs in React applications. It is part of the Chakra UI library, offering a set of components for building consistent and accessible user interfaces. This component is used for creating interactive and visually appealing modal dialogs. I
2 min read
Chakra UI Feedback Alert
Chakra UI Feedback Alert is used to interrupt the user with a mandatory confirmation or action. The Alert component can be customized by changing its status, which controls the color of the alert. Various alerts could be of different colors. Prerequisites:NPM & NodeReactReact Chakra UISteps To C
2 min read
React Chakra UI Overlay
Chakra UI, a comprehensive React component library, introduces the concept of Overlays serving as dynamic visual elements that are superimposed on the main content, providing additional context, functionality, or notifications. Although Chakra UI doesn't have a standalone "Overlay" component, it off
4 min read
Chakra UI Overlay Popover
Chakra UI Overaly Popover component creates an interactive and visually appealing pop-up overlay in the React application. We can embed the components in realtime usage like basic conformations, customized content, lazy-loaded components, controlled popovers, etc. In this article, we will create the
3 min read
React Suite Modal Alert dialogs
React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application. In this article, we'll learn about React suite Modal alert dialog
5 min read
Chakra UI Overlay Tooltip
Chakra UI's Tooltip component provides concise information when users hover over elements, enhancing user interaction and comprehension. It seamlessly integrates into both development and production stages, streamlining the user experience on websites or apps. Prerequisites:NPM and NodeReactHTML, CS
2 min read
Onsen UI Alert Dialog CSS Components
Onsen UI is a free HTML5 framework that enables you to create unique and practical user interfaces (UI). It also makes UI development simpler, freeing programmers to concentrate on the essential aspects of the project. Onsen UI is a sophisticated collection of user interface elements created especia
3 min read
jQuery UI Dialog create Event
jQuery UI Create event is triggered when the dialog box is created. Learn more about jQuery selectors and events here. Syntax: $(".selector").dialog ( create: function( event, ui ) { console.log('created') },Approach: First, add jQuery Mobile scripts needed for your project.<link href = "https://
2 min read
Chakra UI Disclosure
Chakra UIÂ is a powerful component library for React that is designed and developed by Segun Adebayo to build front-end applications. The Chakra UI comes with simple yet easy-to-understand documentation that gives us guidelines on how to build a reusable component. In this article, we will learn abou
5 min read
Blaze UI Basic Overlay
Blaze UI is a free open source UI Toolkit that provides a great structure for building websites quickly with a scalable and maintainable foundation. All components in Blaze UI are developed mobile-first and rely solely on native browser features, not a separate library or framework. It helps us to c
2 min read