Drawer

Drawers slide in from a container to expose additional options and information.

Drawers slide in from a container to expose additional options and information.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close Open Drawer

By default, drawers slide in from the right. To make the drawer slide in from the left, set the placement attribute to start.

This drawer slides in from the start. Close Open Drawer

To make the drawer slide in from the top, set the placement attribute to top.

This drawer slides in from the top. Close Open Drawer

To make the drawer slide in from the bottom, set the placement attribute to bottom.

This drawer slides in from the bottom. Close Open Drawer

By default, drawers slide out of their containing block, which is usually the viewport. To make a drawer slide out of a parent element, add the contained attribute to the drawer and apply position: relative to its parent.

Unlike normal drawers, contained drawers are not modal. This means they do not show an overlay, they do not trap focus, and they are not dismissible with Escape. This is intentional to allow users to interact with elements outside of the drawer.

The drawer will be contained to this box. This content won't shift or be affected in any way when the drawer opens. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close
Toggle Drawer

Use the —size custom property to set the drawer’s size. This will be applied to the drawer’s width or height depending on its placement.

This drawer is always 50% of the viewport. Close Open Drawer

By design, a drawer’s height will never exceed 100% of its container. As such, drawers will not scroll with the page to ensure the header and footer are always accessible to the user.

Scroll down and give it a try! 👇

Close
Open Drawer

The header shows a functional close button by default. You can use the header-actions slot to add additional icon buttons if needed.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close Open Drawer

By default, drawers will close when the user clicks the close button, clicks the overlay, or presses the Escape key. In most cases, the default behavior is the best behavior in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur.

To keep the drawer open in such cases, you can cancel the ods-drawer-request-close event. When canceled, the drawer will remain open and pulse briefly to draw the user’s attention to it.

You can use event.detail.source to determine what triggered the request to close. This example prevents the drawer from closing when the overlay is clicked, but allows the close button or Escape to dismiss it.

This drawer will not close when you click on the overlay. Close Open Drawer

By default, the drawer’s panel will gain focus when opened. This allows a subsequent tab press to focus on the first tabbable element in the drawer. If you want a different element to have focus, add the autofocus attribute to it as shown below.

Close Open Drawer

You can further customize initial focus behavior by canceling the sense-drawer-initial-focus event and setting focus yourself inside the event handler.
import '@ods/components/web.drawer';

Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.

Slots

NameDescription
(default)The drawer's main content.
labelThe drawer's label. Alternatively, you can use the `label` attribute.
header-actionsOptional actions to add to the header. Works best with `<ods-icon-button>`.
footerThe drawer's footer, usually one or more buttons representing various options.

Properties

Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.

Property/AttributeReflectsTypeDefault
modal
new Modal(this)
open
booleanfalse
label
string''
placement
'top' | 'end' | 'bottom' | 'start''end'
contained
booleanfalse
noHeader
no-header
booleanfalse

Events

React EventDescriptionEvent Detail
ods-drawer-showEmitted when the drawer opens.--
ods-drawer-after-showEmitted after the drawer opens and all animations are complete.--
ods-drawer-hideEmitted when the drawer closes.--
ods-drawer-after-hideEmitted after the drawer closes and all animations are complete.--
ods-drawer-initial-focusEmitted when the drawer opens and is ready to receive focus. Calling `event.preventDefault()` will prevent focusing and allow you to set it on a different element, such as an input.--
ods-drawer-request-closeEmitted when the user attempts to close the drawer by clicking the close button, clicking the overlay, or pressing escape. Calling `event.preventDefault()` will keep the drawer open. Avoid using this unless closing the drawer will result in destructive behavior such as data loss.--

Methods

NameDescriptionArguments
show()Shows the drawer.--
hide()Hides the drawer--

Parts

NameDescription
baseThe component's base wrapper.
overlayThe overlay that covers the screen behind the drawer.
panelThe drawer's panel (where the drawer and its content are rendered).
headerThe drawer's header. This element wraps the title and header actions.
header-actionsOptional actions to add to the header. Works best with `<ods-icon-button>`.
titleThe drawer's title.
close-buttonThe close button, an `<ods-icon-button>`.
close-button__baseThe close button's exported `base` part.
bodyThe drawer's body.
footerThe drawer's footer.

Dependencies

This component automatically imports the following dependencies.

  • ods-icon
  • ods-icon-button

Search