MessageBarGroup
A stack of MessageBars that animates the bars it gains and loses, Fluent's MessageBarGroup with its animate prop: a bar removed from the children fades out while its row closes, so the bars below glide up instead of jumping (Fluent's bar only fades, and the bars below jump when it is gone), and with animate="both" a bar added after mount opens its row and fades in.
- **Keys.** Give every bar a stable key (key={message.id}): the group follows its children by key, so it can keep a removed bar on screen during its exit, in its place, and move bars that are reordered without replacing them. A removed bar that comes back during its exit is shown again. A child without a key of its own, or text, renders after the bars as given, without motion, with a development warning. Any keyed element animates; MessageBar is the one the group is made for.
- **Motion.** Bars present at the group's first render (on the server too) never animate. Each bar sits in an element of its own, which renders no box while the bar is shown, so the bars are the stack's own items; while a bar enters or exits, that element clips it while its row opens or closes. An exiting bar is inert. See motion for the default and how to replace or turn it off; under prefers-reduced-motion: reduce a bar is added and removed at once.
- **Focus.** When a bar leaves with focus inside it (its Dismiss button was pressed), focus moves in the same commit to the first tabbable element of the nearest bar after it that stays and holds a tabbable element, else of the nearest such bar before it. When no such bar is left, the app decides where focus goes.
- **Markup.** A plain <div> without a role stacking the bars with an 8px gap; each MessageBar stays its own live region. MessageBarGroup is a component of its own rather than a part of MessageBar, so a page that imports only MessageBar does not load the group's motion.
Examples
Exit Only
export const ExitOnly: Story = {
render: (args) => <MessageBarGroupDemo {...args} label="exit only" />,
};Animate Both
export const AnimateBoth: Story = {
args: { animate: 'both' },
render: (args) => <MessageBarGroupDemo {...args} label="both" />,
};Motion
export const Motion: Story = {
args: { animate: 'both' },
render: (args) => (
<div className="flex flex-col gap-8">
{motionCases(slowFadeAndCollapse).map(({ label, motion }) => (
// The story renders one group per case; every other arg is forwarded.
<MessageBarGroupDemo key={label} {...args} label={label.toLowerCase()} motion={motion} />
))}
</div>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
animate | 'exit-only' | 'both' | No | 'exit-only' | Which changes animate: |
motion | MotionSlot | null | No | the collapse and fade above | Replaces the bars' motion (both directions); |
children | React.ReactNode | No | MessageBar elements, each with a stable | |
ref | React.Ref<HTMLDivElement> | No | Ref to the root |
Any other prop is passed to the element it renders (HTMLDivElement).
Stable class names
| Part | Class |
|---|---|
root | wave-message-bar-group |
item | wave-message-bar-group__item |