Skip to content

MessageBar

MessageBar

An inline message that tells the user about the state of a page or task: a status icon, a visually hidden status label ("Warning:"), an optional title, the message, optional actions and an optional dismiss button.

- The status sets the tint, the logical start border, the icon and the role (alert for warning/error, status otherwise); politeness sets the role by urgency instead (assertive is alert, polite is status). Screen readers hear the severity through statusLabel. shape="square" removes the rounded corners of a bar that spans the page.
- Parts, as direct children: MessageBar.Title (a semibold lead-in, read first after the severity) and MessageBar.Actions (buttons after the text on one row, or below it with layout="multiline"). The built-in Dismiss button stays the bar's own.
- With its default roles the bar is a live region and the title is read as the start of its content; give the bar role="region" (a notice that stays on the page) and the title names it.
- The dismiss button is always the MessageBar's own <button> wired to onDismiss (type="button" unless a merged button slot sets its own type); the dismiss slot only replaces its content (see MessageBarProps.dismiss).
- Content of your own anywhere in the bar (an action that follows it, for example) reads the bar's status and the layout it renders, after layout="auto" has measured, through useMessageBarContext.

React Server Components cannot dot into a client module: import the flat names MessageBarTitle and MessageBarActions there; MessageBar.Title and MessageBar.Actions work in client files.

Examples

Info

Info: This is an informational message.
export const Info: Story = {};

Success

Success: Operation completed successfully.
export const Success: Story = {
  args: {
    status: 'success',
    children: 'Operation completed successfully.',
  },
};

Warning

export const Warning: Story = {
  args: {
    status: 'warning',
    children: 'Please review your input before continuing.',
  },
};

Error

export const Error: Story = {
  args: {
    status: 'error',
    children: 'Something went wrong. Please try again.',
  },
};

Dismissible

Info: This message can be dismissed.
export const Dismissible: Story = {
  args: {
    children: 'This message can be dismissed.',
    onDismiss: fn(),
  },
  render: (args) => <DismissibleMessageBar {...args} />,
};

Custom Dismiss Content

export const CustomDismissContent: Story = {
  args: {
    status: 'warning',
    children: 'Your session expires in 5 minutes.',
    onDismiss: fn(),
    dismiss: {
      children: 'Close',
      'aria-label': 'Close',
      className: 'px-1 text-wave-caption-1 font-semibold',
    },
  },
  render: (args) => <DismissibleMessageBar {...args} />,
};

Localized Status

Erfolg: Die Änderungen wurden gespeichert.
export const LocalizedStatus: Story = {
  args: {
    status: 'success',
    statusLabel: 'Erfolg:',
    children: 'Die Änderungen wurden gespeichert.',
    lang: 'de',
  },
};

With Title

export const WithTitle: Story = {
  args: {
    status: 'warning',
    children: (
      <>
        <MessageBar.Title>Update available</MessageBar.Title>A new version is ready to install.
      </>
    ),
  },
};

With Actions

export const WithActions: Story = {
  args: {
    status: 'error',
    onDismiss: fn(),
    children: (
      <>
        <MessageBar.Title>Upload failed</MessageBar.Title>The file is larger than 10 MB.
        <MessageBar.Actions>
          <Button size="small">Retry</Button>
          <Button size="small" appearance="subtle">
            Details
          </Button>
        </MessageBar.Actions>
      </>
    ),
  },
  render: (args) => <DismissibleMessageBar {...args} />,
};

Multiline

Success: Backup complete All 1,204 files were copied to the archive.
export const Multiline: Story = {
  args: {
    status: 'success',
    layout: 'multiline',
    children: (
      <>
        <MessageBar.Title>Backup complete</MessageBar.Title>All 1,204 files were copied to the
        archive.
        <MessageBar.Actions>
          <Button size="small">Open archive</Button>
        </MessageBar.Actions>
      </>
    ),
  },
};

Reflow

export const Reflow: Story = {
  args: {
    status: 'warning',
    children: (
      <>
        <MessageBar.Title>Storage almost full</MessageBar.Title>You have used 9.6 GB of your 10 GB
        plan.
        <MessageBar.Actions>
          <Button size="small">Upgrade</Button>
          <Button size="small" appearance="subtle">
            Manage files
          </Button>
        </MessageBar.Actions>
      </>
    ),
  },
  render: (args) => (
    <div className="w-[720px] min-w-[240px] max-w-full resize-x overflow-hidden p-1">
      <MessageBar {...args} />
    </div>
  ),
};

Region Notice

Warning: Maintenance tonight The service is unavailable from 22:00 to 23:00 UTC.
export const RegionNotice: Story = {
  args: {
    status: 'warning',
    role: 'region',
    children: (
      <>
        <MessageBar.Title>Maintenance tonight</MessageBar.Title>The service is unavailable from
        22:00 to 23:00 UTC.
      </>
    ),
  },
};

Status-aware action

export const StatusAwareAction: Story = {
  name: 'Status-aware action',
  args: {
    status: 'error',
    children: (
      <>
        <MessageBar.Title>Sync failed</MessageBar.Title>Your last three changes were not saved to
        the server.
        <MessageBar.Actions>
          <StatusAction onAction={fn()} />
        </MessageBar.Actions>
      </>
    ),
  },
  render: (args) => (
    <div className="w-[720px] min-w-[240px] max-w-full resize-x overflow-hidden p-1">
      <MessageBar {...args} />
    </div>
  ),
};

Square

export const Square: Story = {
  args: { shape: 'square', status: 'warning', children: 'Your trial ends in three days.' },
};

Politeness

Error: The sync failed and will retry (announced politely).
export const Politeness: Story = {
  render: () => (
    <div className="flex flex-col gap-3">
      <MessageBar status="error" politeness="polite">
        The sync failed and will retry (announced politely).
      </MessageBar>
      <MessageBar status="info" politeness="assertive">
        The session ends in one minute (announced at once).
      </MessageBar>
    </div>
  ),
};

Props

NameTypeRequiredDefaultDescription
status'success' | 'warning' | 'error' | 'info'No'info'

Status level controlling the color, icon, status text and role of the message bar. warning and error render role="alert", info and success role="status" (a consumer role wins).

shape'square' | 'rounded'No'rounded'

Corners of the bar: rounded (the default) or square, for a bar that spans the page or the width of a card. The root carries it as data-shape. Fluent's shape.

politeness'polite' | 'assertive'Noby status: assertive for `warning` and `error`, polite otherwise

How urgently the bar is announced when it appears or its content changes: assertive renders role="alert" (read at once), polite renders role="status" (read when the reader is idle). Without it the status decides: warning and error are assertive, info and success polite. A role of yours wins over both. Fluent's politeness, which it applies through its announcer region: here the bar is its own live region.

statusLabelstringNo

Visually hidden text read before the message so screen-reader users hear the severity ('Info:', 'Success:', 'Warning:', 'Error:' by default). Pass a translation for other languages, or '' when the message text already states the severity.

onDismiss() => voidNo

Called when the dismiss button is activated. Passing it renders the dismiss button (unless dismiss is null).

iconSlot<'span'>No

Custom status icon, rendered decoratively (aria-hidden="true", a slot object can override it) in the status color. Only undefined keeps the default status icon; null, or anything that renders nothing (false, ''), shows no icon.

dismissSlot<'span'>No

Content of the dismiss button (replaces the default dismiss icon). It always renders **inside** the built-in <button type="button" aria-label="Dismiss">, which calls onDismiss; passing content shows the dismiss button even without onDismiss. null is the only value that hides the button. A boolean counts as no slot, so the conditional idiom dismiss={useBrandIcon && <BrandCloseIcon />} keeps the default button: the default icon with onDismiss, no button without it. Content that renders nothing ('', or an array or Fragment of only null, false, true and '', also as the children of a slot object or a merged button) keeps the default icon, so the button is never empty; a slot object that renders a component or a void element ({ as: CloseIcon }, { as: 'img', src, alt: '' }) or sets dangerouslySetInnerHTML is the icon itself. The content is decorative (aria-hidden), so the button keeps the name "Dismiss": when the content is visible text, pass a slot object whose aria-label matches it ({ children: 'Close', 'aria-label': 'Close' }) so the name contains the visible label. An aria-label, aria-labelledby or title on a slot object names the button instead of "Dismiss".

A <button> element or a Wave Button passed here is not nested: its props are merged into the built-in button (its onClick runs first and can call preventDefault() to cancel onDismiss; its aria-label and an explicit type win over the defaults) and its content (children, or dangerouslySetInnerHTML markup) is used as is, with a development warning. A Wave Button's own props are not attributes: its icon becomes decorative content before its children (after them with iconPosition="after"), disabledFocusable makes the dismiss button unavailable but focusable as on the Button (onDismiss is not called), and appearance and size are ignored. When the rendered content has a text label (at least two letters or digits: <button>Close</button>, or text rendered by a component such as a translation), that text names the button, as in 0.4. An icon, a lone character (X, ×, +: a symbol, not a label) and text that is aria-hidden or hidden keep the name "Dismiss". Text hidden only with CSS still counts as the label: a responsive label such as <span className="hidden sm:inline">Close</span> drops the default name, so the button has no name wherever that text is not displayed. Give such a button an explicit aria-label (<button aria-label="Close">…</button>). An aria-label, aria-labelledby or title on the element names the button.

A slot object is the content element, not the button: its attributes, className, style, ref and event handlers included, go to that element (only the naming attributes above reach the button), so handle the press in onDismiss. A slot object whose as is a <button> or a Wave Button cannot render inside the button: its children render as the content (the default icon when it has none) and its props are dropped, with a development warning.

slotProps.dismissButton reaches the same button; its attributes replace those of a merged button (see there).

layout'auto' | 'singleline' | 'multiline'No'auto'

How the text and the actions share the bar. 'singleline': the actions sit on the text's row (the text wraps inside its column; it is never cut off). 'multiline': the actions get a row of their own under the text. 'auto': the actions stay on the text's row while the text fits on one line, measured after mount (the server renders one row), and move below it otherwise; a bar without MessageBar.Actions is 'multiline', the 0.7 look. The root renders the layout in use as data-layout (singleline or multiline). Fluent's layout.

childrenReact.ReactNodeYes

The message: body text, with the parts MessageBar.Title and MessageBar.Actions as direct children (see the component docs).

refReact.Ref<HTMLDivElement>No

Ref to the root <div>.

slotProps{ body?: SlotPart<'div'>; dismissButton?: SlotPart<'button'> }No

Props for the element the bar draws around your message and for its Dismiss button, by part, merged into each part's own (Fluent UI writes the text as a MessageBarBody and the Dismiss button as the containerAction slot of its MessageBarActions): your classes after the part's (yours win a conflict), your styles over its styles, your handlers before its handlers, your ids added to its aria-labelledby and aria-describedby, and your ref beside its ref. Every attribute the bar sets on a part is locked and keeps the bar's value; you add the attributes it does not set. A part takes no children: your children fill the text column, and dismiss fills the Dismiss button. icon is a slot of its own.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • body
  • dismissButton
  • MessageBar.Title
  • MessageBar.Actions

Stable class names

PartClass
rootwave-message-bar
iconwave-message-bar__icon
bodywave-message-bar__body
dismissButtonwave-message-bar__dismiss-button
dismissIconwave-message-bar__dismiss-icon