Skip to content

MessageBarGroup

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

Success: Your profile was saved.
export const ExitOnly: Story = {
  render: (args) => <MessageBarGroupDemo {...args} label="exit only" />,
};

Animate Both

Success: Your profile was saved.
export const AnimateBoth: Story = {
  args: { animate: 'both' },
  render: (args) => <MessageBarGroupDemo {...args} label="both" />,
};

Motion

Success: Your profile was saved.
Success: Your profile was saved.
Success: Your profile was saved.
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

NameTypeRequiredDefaultDescription
animate'exit-only' | 'both'No'exit-only'

Which changes animate: 'exit-only' (a bar removed from the children fades and collapses out) or 'both' (a bar added after mount also fades and slides in). Bars present at the group's first render never animate. Fluent's animate. The root renders it as data-animate.

motionMotionSlot | nullNothe collapse and fade above

Replaces the bars' motion (both directions); null turns it off. The motion is on the element around each bar (className stays on the root). By default a removed bar fades out while its row and its bottom margin close over 250 ms with the linear curve, so the bars after it glide up and nothing jumps when it unmounts (the margin makes up for the group's 8px gap, so a different gap in className needs a motion whose margin matches it); with animate="both", a bar added after mount opens its row and fades in the same way. Under reduced motion bars appear and disappear at once. null turns the motion off (the element still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. A WaveUI addition: Fluent's MessageBarGroup has no motion slot (its bar only fades out).

childrenReact.ReactNodeNo

MessageBar elements, each with a stable key.

refReact.Ref<HTMLDivElement>No

Ref to the root <div>.

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

Stable class names

PartClass
rootwave-message-bar-group
itemwave-message-bar-group__item