Notice


目录

Use Notices to communicate prominent messages to the user.

Notice component

Design guidelines

A Notice displays a succinct message. It can also offer the user options, like viewing a published post or updating a setting, and requires a user action to be dismissed.

Use Notices to communicate things that are important but don’t necessarily require action — a user can keep using the product even if they don’t choose to act on a Notice. They are less interruptive than a Modal.

Usage

Notices display at the top of the screen, below any toolbars anchored to the top of the page. They’re persistent and non-modal. Since they don’t overlay the content, users can ignore or dismiss them, and choose when to interact with them.

Notices are color-coded to indicate the type of message being communicated:

If an icon is included in the Notice, it should be color-coded to match the Notice state.

Do’s and Don’ts

Do use a Notice when you want to communicate a message of medium importance.

A success Notice for updating a post

Don’t use a Notice for a message that requires immediate attention and action from the user. Use a Modal for this instead.

A Notice that requires an immediate action

Do display Notices at the top of the screen, below any toolbars.

A success Notice for publishing a post

Don’t show Notices on top of toolbars.

A success Notice on top of the editor toolbar

Do use color to indicate the type of message being communicated.

An error Notice using red

Don’t apply any colors other than those for Warnings, Success, or Errors.

An error Notice using purple

Development guidelines

Usage

To display a plain notice, pass Notice a string:

import { Notice } from '@wordpress/components';

const MyNotice = () => (
    <Notice status="error">An unknown error occurred.</Notice>
);

For more complex markup, you can pass any JSX element:

import { Notice } from '@wordpress/components';

const MyNotice = () => (
    <Notice status="error">
        <p>
            An error occurred: <code>{ errorDetails }</code>.
        </p>
    </Notice>
);

Props

The following props are used to control the behavior of the component.

children: ReactNode

The displayed message of a notice. Also used as the spoken message for assistive technology, unless spokenMessage is provided as an alternative message.

spokenMessage: ReactNode

Used to provide a custom spoken message in place of the children default.

status: 'warning' | 'success' | 'error' | 'info'

Determines the color of the notice: warning (yellow), success (green), error (red), or 'info'. By default 'info' will be blue.

onRemove: () => void

A function called to dismiss/remove the notice.

politeness: 'polite' | 'assertive'

A politeness level for the notice’s spoken message. Should be provided as one of the valid options for an aria-live attribute value.

Note that this value should be considered a suggestion; assistive technologies may override it based on internal heuristics.

isDismissible: boolean

Whether the notice should be dismissible or not

onDismiss : () => void

A deprecated alternative to onRemove. This prop is kept for compatibility reasons but should be avoided.

actions: Array<NoticeAction>.

An array of notice actions. Each member object should contain:

The default variant of an action button is 'secondary' if only onClick is provided, or 'link' if url is provided.


版本号 #2
由 壳壳虫 创建于 2026-10-31 18:14:05 UTC
由 壳壳虫 更新于 2026-10-31 18:14:06 UTC