Alert

Alerts are temporary notifications that provide concise feedback about an action or event.


Installation

npx nextui-cli@latest add alert
The above command is for individual installation only. You may skip this step if @nextui-org/react is already installed globally.

Import

Usage

Colors

Alert comes with 6 color variants to convey different meanings.

Variants

Radius

With Icon

By default, Alert displays an appropriate icon based on the color prop. You can override this by providing a custom icon using the icon prop.

With Action

Alert supports an endContent prop for additional actions.

Controlled Visibility

You can control the alert visibility using the isVisible and onVisibleChange props.

Custom Styles

You can customize the alert by passing custom Tailwind CSS classes to the component slots.

Custom Implementation

You can use the useAlert hook to create your own alert component.

Data Attributes

Alert has the following attributes on the base element:

  • data-visible: When the alert is visible
  • data-closeable: When the alert can be closed
  • data-has-title: When the alert has a title
  • data-has-description: When the alert has a description

Slots

Alert has the following slots:

  • base: The main alert container element
  • title: The title element
  • description: The description element
  • mainWrapper: The wrapper for the title and description content
  • closeButton: The close button element
  • iconWrapper: The wrapper for the alert icon
  • alertIcon: The alert icon element

Accessibility

  • Alert has role of alert
  • Close button has aria-label="Close" by default
  • When closed, alert is removed from the DOM

API

Alert Props

AttributeTypeDescriptionDefault
titlestringThe alert title-
iconReactNodeThe alert icon - overrides the default icon-
descriptionReactNodeThe alert description-
colordefault | primary | secondary | success | warning | dangerThe alert color themedefault
variantsolid | bordered | flat | fadedThe alert variantflat
radiusnone | sm | md | lg | fullThe alert border radiusmd
startContentReactNodeThe alert start content-
endContentReactNodeThe alert end content-
isVisiblebooleanWhether the alert is visible-
isClosablebooleanWhether the alert can be closedfalse
hideIconbooleanWhether the icon is hiddenfalse
hideIconWrapperbooleanWhether the icon wrapper is hiddenfalse
closeButtonPropsButtonPropsProps for the close button-

Alert Events

AttributeTypeDescription
onClose() => voidHandler called when the close button is clicked
onVisibleChange(isVisible: boolean) => voidHandler called when the alert visibility changes