JGuang

Alert

Alert · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Alert

Display warning messages that require attention.

When To Use

  • When you need to show alert messages to users.
  • When you need a persistent static container which is closable by user actions.

Examples

  • Basic · basic

  • More types · style

  • Filled · filled

  • Closable · closable

  • Description · description

  • Icon · icon

  • Banner · banner

  • Loop Banner · loop-banner

  • Smoothly Unmount · smooth-closed

  • ErrorBoundary · error-boundary

  • Custom action · action

  • Custom title alignment · custom-title-alignment

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersionGlobal Config
actionThe action of AlertReactNode-×
afterCloseCalled when close animation is finished, please use closable.afterClose instead() => void-×
bannerWhether to show as bannerbooleanfalse×
variantVariant of Alert styleoutlined | filledoutlined6.4.06.4.0
classNamesCustomize class for each semantic structure inside the component. Supports object or functionRecord<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-6.0.0
closableThe config of closableboolean | ClosableType & React.AriaAttributesfalseclosable.closeIcon, closable.aria-*: 5.15.0
closeIcon(Only supports global configuration) Custom close iconReactNode-×5.14.0
descriptionAdditional content of AlertReactNode-×
errorIcon(Only supports global configuration) Custom error icon in Alert iconReactNode-×6.2.0
iconCustom icon, effective when showIcon is trueReactNode-×
infoIcon(Only supports global configuration) Custom info icon in Alert iconReactNode-×6.2.0
messageContent of Alert, please use title insteadReactNode-×
onCloseCallback when Alert is closed, please use closable.onClose instead(e: MouseEvent) => void-×
closeIconCustom close icon, please use closable.closeIcon insteadReactNode--×
closeTextClose text to show, please use closable.closeIcon insteadReactNode--×
showIconWhether to show iconbooleanfalse, in banner mode default is true×
stylesCustomize inline style for each semantic structure inside the component. Supports object or functionRecord<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-6.0.0
successIcon(Only supports global configuration) Custom success icon in Alert iconReactNode-×6.2.0
titleContent of AlertReactNode-×
typeType of Alert styles, options: success, info, warning, errorstringinfo, in banner mode default is warning×
warningIcon(Only supports global configuration) Custom warning icon in Alert iconReactNode-×6.2.0

ClosableType

PropertyDescriptionTypeDefaultVersion
afterCloseCalled when close animation is finishedfunction--
closeIconCustom close iconReactNode--
onCloseCallback when Alert is closed(e: MouseEvent) => void--

Alert.ErrorBoundary

PropertyDescriptionTypeDefaultVersion
descriptionCustom error description to showReactNode{{ error stack }}
messageCustom error message to show, please use title insteadReactNode{{ error }}
titleCustom error title to showReactNode{{ error }}

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with border, background, padding, border-radius, and positioning styles for the alert container6.0.0
iconIcon element with color, line-height, and margin styles, supporting different status icon types6.0.0
sectionContent element with flex layout controlling content area typography and minimum width6.0.0
titleTitle element with text color and font styling for the alert title6.0.0
descriptionDescription element with font-size and line-height styles for additional content6.0.0
actionsActions element with layout and spacing styles for action buttons6.0.0
closeClose button element with basic button styling6.1.0

Semantic description source: vendor/components/alert/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
borderRadiusCSSProperties['borderRadius']Border radius of alert
defaultPaddingCSSProperties['padding']Default padding
withDescriptionPaddingCSSProperties['padding']Padding with description
withDescriptionIconSizenumber | stringIcon size with description

Declaration source: vendor/components/alert/style/index.ts

import type { CSSProperties } from 'react';

import type { CSSObject } from '@ant-design/cssinjs';

import { unit } from '@ant-design/cssinjs';

import { genFocusStyle, resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks } from '../../theme/internal';

export interface ComponentToken {
  // Component token here
  /**
   * @desc 组件圆角
   * @descEN Border radius of alert
   * @since 6.6.0
   */
  borderRadius: CSSProperties['borderRadius'];
  /**
   * @desc 默认内间距
   * @descEN Default padding
   */
  defaultPadding: CSSProperties['padding'];
  /**
   * @desc 带有描述的内间距
   * @descEN Padding with description
   */
  withDescriptionPadding: CSSProperties['padding'];
  /**
   * @desc 带有描述时的图标尺寸
   * @descEN Icon size with description
   */
  withDescriptionIconSize: number | string;
}

type AlertToken = FullToken<'Alert'> & {
  // Custom token here
};

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/alert/Alert.tsx
  • vendor/components/alert/ErrorBoundary.tsx
  • vendor/components/alert/index.tsx
  • vendor/components/alert/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.