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
export const Info: Story = {};Success
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
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
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
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
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
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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
status | 'success' | 'warning' | 'error' | 'info' | No | 'info' | Status level controlling the color, icon, status text and role of the message bar. |
shape | 'square' | 'rounded' | No | 'rounded' | Corners of the bar: |
politeness | 'polite' | 'assertive' | No | by status: assertive for `warning` and `error`, polite otherwise | How urgently the bar is announced when it appears or its content changes: |
statusLabel | string | No | Visually hidden text read before the message so screen-reader users hear the severity ( | |
onDismiss | () => void | No | Called when the dismiss button is activated. Passing it renders the dismiss button (unless | |
icon | Slot<'span'> | No | Custom status icon, rendered decoratively ( | |
dismiss | Slot<'span'> | No | Content of the dismiss button (replaces the default dismiss icon). It always renders **inside** the built-in A A slot object is the content element, not the button: its attributes,
| |
layout | 'auto' | 'singleline' | 'multiline' | No | 'auto' | How the text and the actions share the bar. |
children | React.ReactNode | Yes | The message: body text, with the parts | |
ref | React.Ref<HTMLDivElement> | No | Ref to the root | |
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 |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
bodydismissButtonMessageBar.TitleMessageBar.Actions
Stable class names
| Part | Class |
|---|---|
root | wave-message-bar |
icon | wave-message-bar__icon |
body | wave-message-bar__body |
dismissButton | wave-message-bar__dismiss-button |
dismissIcon | wave-message-bar__dismiss-icon |