packages/web-components/src/message-bar/README.md
A MessageBar communicates important information about the state of the entire product or surface—for example, the status of a page, panel, dialog, or card. The information shouldn’t require someone to take immediate action and can never be used to upsell or advertise.
Link to MessageBar Design Spec in Figma: Link
The Fabric WC3 MessageBar extends FASTElement
MessageBar<slot name="icon"></slot>
<div class="content">
<slot></slot>
</div>
<div class="actions">
<slot name="actions"></slot>
</div>
<slot name="dismiss"></slot>
| Name | Type | Description |
|---|---|---|
MessageBarLayout | multiline singleline | How text flows within the MessageBar |
MessageBarShape | rounded square | Shapes for the MessageBar |
MessageBarIntent | success warning error info | Intents for the MessageBar |
| Name | Type | Default | Description |
|---|---|---|---|
layout | multiline singleline | singleline | Determines if the MessageBar should opt out of automatic reflow for applications that have an existing responsive design mechanism |
shape | square rounded | rounded | Determines the shape of the corners on the MessageBar |
intent | success warning error info | info | Sets the intent type for the MessageBar |
| Name | Type | Description |
|---|---|---|
dismiss | CustomEvent | Fires when the MessageBar is dismissed. |
| Name | Privacy | Description |
|---|---|---|
dismiss | public | Hides the MessageBar. |
| Name | Description |
|---|---|
| The default slot for the main content | |
icon | The slot for the icon to represent intent |
actions | The slot for optional action buttons |
dismiss | The slot for a custom close icon |
role="status"
aria-live
aria-live attribute should be used to associate the MessageBar with the appropriate aria-live value to announce content changes to assistive technology devices.aria-labelledby
aria-labelledby attribute should be used to associate the MessageBar with an element that serves as its accessible label or title, often the title is within the content passed to the default slot.Layout Attribute Values and Defaults
The Fluent React v9 Message Bar includes an option for the layout attribute to be set to auto, singleline, or multiline. It leverages the ResizeObserver API to detect the height of the default slot and adjust the layout based on whether the content wraps or not. While this approach is effective, it introduces complexity and significantly increases the component’s size.
In contrast, the web component version delegates the responsibility of adjusting the layout according to the content to the implementor. By default, the layout attribute is set to singleline. This approach reduces the component’s size, offers greater flexibility, and aligns with the intended design. It acknowledges that the slot content resides in the light DOM, allowing for more efficient management of layout changes.
Component and Slot Mapping
| Fluent UI React 9 | Fluent Web Components 3 |
|---|---|
<MessageBarActions> | slot="actions" |
<MessageBarActions> > containerAction() | slot="close" |
<MessageBarBody> | default slot |
<MessageBarTitle> | default slot |