Etch component
Drawer 1
Documentation
A drawer that slides in from any edge, with drag to close, from Nick Arce's drawer template. Use it for mobile menus, filters, carts, forms or anything that shouldn't take a whole page. Put its content in the body slot; the drawer patterns in this library show full examples.
How to use it
- Give each drawer a Unique ID, then set the Open Trigger Selector (for example
#open-menu) and, if it has one, the Close Trigger Selector. - Choose the Open Direction: bottom, left, right or top.
- Auto Open opens it after a delay, with a reshow rule, such as once or until it's dismissed. Passive Mode keeps the page usable behind it, with no overlay.
- Show In Builder opens it in Etch while you edit it.
Good to know
- Dragging, Escape and a click on the overlay close it, and focus goes back to the button that opened it. Disable Drag to Close and Drag Handle Only limit dragging, and Close Anchor Link closes it when a link inside it jumps to a section on the page.
- The CSS variables set its background, radius, sizes, overlay color and timing.
- A drawer inside another drawer moves itself to the end of the page, so its overlay covers the whole screen.
- For your own CSS, the states are data attributes:
[data-visible="true"]on the wrapper while the drawer shows,[data-state="open"]on the drawer, and[data-dragging="true"]during a drag.
Reference
Read from the component's JSON, so it's always current.
Loading the reference