packages/react-components/react-drawer/library/docs/Spec.md
A Drawer's main function is to contain supplementary content and are used for complex creation, edit, or management experiences. For example, viewing details about an item in a list or editing settings. It is also useful to host navigational elements that can be visible at all times.
The Drawer don't have any content built in, but has mechanisms to display it in a structured way.
The Panel component on v8's version is very similar to what Drawer component is structured. It has an opinionated way to provide content, like header text and a close button.
<Panel headerText="Sample panel" isOpen={isOpen} onDismiss={dismissPanel} closeButtonAriaLabel="Close">
<p>Content goes here.</p>
</Panel>
There is not prior implementation for this component in v0
<Drawer open={open} onOpenChange={(_, { open }) => setOpen(open)}>
<p>Content goes here.</p>
</Drawer>
OverlayDrawer:
Opens on top of everything like a dialog and blocks all the page content. Can be dismissed.
InlineDrawer:
Push the siblings content when open and it is non-blocking. Can be hidden to bring focus to the main content of the page.
small (default): 320pxmedium: 592pxlarge: 940pxfull: 100vwFor any custom size, a style can be provided overriding the width of drawer. Drawer can never be extended beyond screen limits and in case the size is larger than the screen size, it'll act as a full Drawer.
By default, the OverlayDrawer acts as a modal, rendering an overlay scrim behind the drawer surface. This can be toggled off.
This component is a combination of both InlineDrawer and OverlayDrawer
| Property | Values | Default | Description |
|---|---|---|---|
| type | overlay, inline | overlay | Set the type of Drawer |
| position | start, end, bottom | start | Set the position of the Drawer |
| size | small, medium, large, full | small | The drawer width size |
| modalType | boolean | true | Set the visibility of the backdrop scrim. Only for type="overlay" |
| inertTrapFocus | boolean | true | Enables standard behavior according to the HTML dialog spec. Only for type="overlay" |
| open | boolean | false | Define the Drawer visibility |
| defaultOpen | boolean | false | Define the Drawer visibility on first render |
| onOpenChange | function | undefined | Callback called when drawer changes its visibility. Only for type="overlay" |
| separator | boolean | false | Define if the type="inline" drawer should render a separator |
| Slots | Values | Default | Description |
|---|---|---|---|
| root | div | div | The root drawer element |
| Property | Values | Default | Description |
|---|---|---|---|
| position | start, end, bottom | start | Set the position of the Drawer |
| size | small, medium, large, full | small | The drawer width size |
| modalType | boolean | true | Set the visibility of the backdrop scrim |
| inertTrapFocus | boolean | true | Enables standard behavior according to the HTML dialog spec |
| open | boolean | false | Define the Drawer visibility |
| defaultOpen | boolean | false | Define the Drawer visibility on first render |
| onOpenChange | function | undefined | Callback called when drawer changes its visibility |
| Slots | Values | Default | Description |
|---|---|---|---|
| root | div | div | The root overlay drawer element |
| Property | Values | Default | Description |
|---|---|---|---|
| position | start, end, bottom | start | Set the position of the Drawer |
| size | small, medium, large, full | small | The drawer width size |
| open | boolean | false | Define the Drawer visibility |
| defaultOpen | boolean | false | Define the Drawer visibility on first render |
| separator | boolean | false | Define if the inline drawer should render a separator |
| Slots | Values | Default | Description |
|---|---|---|---|
| root | div | div | The root inline drawer element |
| Slots | Values | Default | Description |
|---|---|---|---|
| root | header | header | The root drawer element |
| Slots | Values | Default | Description |
|---|---|---|---|
| root | nav | nav | The root drawer navigation element |
| Slots | Values | Default | Description |
|---|---|---|---|
| root | div | div | The root drawer title element |
| heading | h2, h1, h3, h4, h5, h6, div | h2 | The root drawer title heading element |
| action | div | div | Action slot for the close button |
No props
| Slots | Values | Default | Description |
|---|---|---|---|
| root | div | div | The root drawer content element |
No props
| Slots | Values | Default | Description |
|---|---|---|---|
| root | footer | footer | The root drawer footer element |
| Component | Purpose |
|---|---|
| Drawer | Renders a plain inline or overlay Drawer and render its children |
| InlineDrawer | Renders a plain inline Drawer and render its children |
| OverlayDrawer | Renders a plain overlay Drawer and render its children |
| DrawerHeader | Renders a header in a structured way. Ideal to display title and actions |
| DrawerHeaderNavigation | Renders a header in a structured way. Ideal to display title and actions |
| DrawerHeaderTitle | Renders a header in a structured way. Ideal to display title and actions |
| DrawerBody | Renders a scrollable div that holds the drawer main content |
| DrawerFooter | Renders a footer element that holds the drawer main actions. Often used to have buttons such as confirmation actions |
type="overlay":<div class="fui-OverlayDrawer" tabindex="-1" role="dialog" aria-modal="true" aria-labelledby="the-title-element-id">
<!-- Content rendered here -->
</div>
type="inline":<div class="fui-InlineDrawer" tabindex="-1" aria-labelledby="the-title-element-id">
<!-- Content rendered here -->
</div>
<header class="fui-DrawerHeader" tabindex="-1" aria-labelledby="the-title-element-id">
<!-- The title content is free, but ideally this should be a heading element -->
<div class="fui-DrawerHeader__title" id="the-title-element-id">Title goes here</div>
<div class="fui-DrawerHeader__actions">
<button type="button" aria-label="Close drawer panel">
<!-- Close button content -->
</button>
<div>
</header>
<header tabindex="-1" aria-labelledby="the-title-element-id">
<nav class="fui-DrawerHeader__navigation">
<button type="button" aria-label="Return back to content">
<!-- Back button content -->
</button>
<button type="button" aria-label="Refresh content">
<!-- Refresh button content -->
</button>
<button type="button" aria-label="Open settings">
<!-- Settings button content -->
</button>
<button type="button" aria-label="Close drawer panel">
<!-- Close button content -->
</button>
</nav>
<!-- The title content is free, but ideally this should be a heading element -->
<div class="fui-DrawerHeader__title" id="the-title-element-id">Title goes here</div>
</header>
<div class="fui-DrawerBody">
<!-- Content rendered here -->
</div>
<footer class="fui-DrawerFooter">
<button type="button">Primary</button>
<button type="button">Secondary</button>
</footer>
DrawerA drawer can be triggered by any button on the screen. When invoked, it slides in from either the start or end sides of the screen. How they behave depends from its type:
overlayThe drawer overlays on top of the main surface. In case the overlay is a modal (by default), it renders an overlay scrim that blocks the whole screen. All the mouse, touch, keyboard and screen readers behaviors will follow the same specs as the Dialog component.
inlineThe drawer pushes content on the main surface to the side to fit. It renders as a div element wherever its placed in the DOM order.
Drawer uses the Dialog under the hood and all accessibility implementation, concerns and recommendations are described in the Dialog component spec.