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
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.
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.
CloseOpen 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.
CloseOpen Drawer
<ods-drawerlabel="Drawer"class="drawer-focus">
<ods-inputautofocusplaceholder="I will have focus when the drawer is opened"></ods-input>
You can further customize initial focus behavior by canceling the sense-drawer-initial-focus event and setting focus yourself inside the event handler.
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.
This component is still in development and cannot be imported at this time.
Slots
Name
Description
(default)
The drawer's main content.
label
The drawer's label. Alternatively, you can use the `label` attribute.
header-actions
Optional actions to add to the header. Works best with `<ods-icon-button>`.
footer
The 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/Attribute
Reflects
Type
Default
modal
new Modal(this)
open
boolean
false
label
string
''
placement
'top' | 'end' | 'bottom' | 'start'
'end'
contained
boolean
false
noHeader
no-header
boolean
false
Events
React Event
Description
Event Detail
ods-drawer-show
Emitted when the drawer opens.
--
ods-drawer-after-show
Emitted after the drawer opens and all animations are complete.
--
ods-drawer-hide
Emitted when the drawer closes.
--
ods-drawer-after-hide
Emitted after the drawer closes and all animations are complete.
--
ods-drawer-initial-focus
Emitted 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-close
Emitted 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
Name
Description
Arguments
show()
Shows the drawer.
--
hide()
Hides the drawer
--
Parts
Name
Description
base
The component's base wrapper.
overlay
The overlay that covers the screen behind the drawer.
panel
The drawer's panel (where the drawer and its content are rendered).
header
The drawer's header. This element wraps the title and header actions.
header-actions
Optional actions to add to the header. Works best with `<ods-icon-button>`.
title
The drawer's title.
close-button
The close button, an `<ods-icon-button>`.
close-button__base
The close button's exported `base` part.
body
The drawer's body.
footer
The drawer's footer.
Dependencies
This component automatically imports the following dependencies.