<hw:drawer>
Base drawer overlay with direction-aware slide transitions, backdrop, focus trap, Escape dismissal and click-outside dismissal.
Basic Usage
<hw:drawer direction="down">
<hw:drawer.trigger>
Open
</hw:drawer.trigger>
<hw:drawer.content>
<hw:drawer.header>
<hw:drawer.title>Notifications</hw:drawer.title>
<hw:drawer.description>Recent activity for your account.</hw:drawer.description>
</hw:drawer.header>
<div class="flex-1 overflow-y-auto p-4">
Content
</div>
<hw:drawer.footer>
<hw:drawer.close>Close</hw:drawer.close>
</hw:drawer.footer>
</hw:drawer.content>
</hw:drawer>
drawer.content must render inside the same drawer root. The root supplies the frame target, direction, axis, backdrop
and motion context used by the dependent content. For Turbo Stream updates, replace the drawer frame or render the owning
Drawer root rather than rendering drawer.content by itself. drawer.trigger does not consume root context and may be
rendered by a standalone partial that lands inside an existing drawer root.
Automatic Behavior
The drawer traps focus while open, restores focus to the trigger on close, locks body scroll by default and closes
synchronously before Turbo caches the page. Its overlay uses data-state="open|closed"; Presence waits for actual
finite CSS motion and cancels stale teardown when the drawer rapidly reopens. Customize transition duration in CSS.
initial-focus="auto" honors an eligible [autofocus] element and otherwise focuses the dialog surface. Use dialog
to skip [autofocus], first-focusable to select the first eligible control, or none to leave focus where it is. With
none, the first Tab or Shift+Tab still enters the trap. Initial focus runs once per opening and is not repeated by
Turbo Frame updates, morph reconnects, or nested-overlay resume.
drawer.title and drawer.description automatically name and describe the dialog overlay. The frame integration assigns
missing ids and refreshes the references when frame content changes.
Set aria-label, aria-labelledby, aria-description, or aria-describedby on <hw:drawer> when the application owns
the accessible text. The component routes these attributes to the semantic dialog overlay for explicit and automatic
frame content, and authored values take precedence over generated title and description references.
Use <hw:sheet> instead when you want a side panel with an always-visible close button.
Frame Content
Use frame when a shared drawer host should load server-rendered content through Turbo Frames:
{{-- layout --}}
<hw:drawer frame="drawer-panel" direction="down" view-transition>
<x-slot:loading_template>
<hw:drawer.title>Loading notifications</hw:drawer.title>
<div class="p-6">Loading...</div>
</x-slot:loading_template>
</hw:drawer>
<a href="{{ route('notifications.index') }}" data-turbo-frame="drawer-panel">
Notifications
</a>
In the destination view, use <hw:frame-or-page>:
<hw:frame-or-page frame="drawer-panel" layout="layouts.app">
<hw:drawer.title>Notifications</hw:drawer.title>
<hw:drawer.description>Your latest account notifications.</hw:drawer.description>
{{-- drawer content or standalone page content --}}
</hw:frame-or-page>
One host can serve different directions and dimensions. On a framed anchor button use
overlay="drawer" overlay-side="right" overlay-size="32rem" as a loading hint; the destination
<hw:frame-or-page> can declare its own direction/size, overriding each hint it supplies. top and bottom map to
up and down; switching between horizontal and vertical also switches width/height CSS variables. Defaults return
on close or abandoned loading. Both the button and the destination need overlay="drawer" for the custom
drawer-panel Frame id above; the family is inferred when the Frame id is drawer. See
presentation per opening.
Include a semantic title in any loading template that opens the drawer. Frame-loaded labels are linked before opening, and explicit unique label ids are preserved.
The drawer guarantees exactly one frame content host. If the slot has no <hw:drawer.content>, it appends an empty host
even alongside a trigger or plain slot content. One content host wraps the frame and uses its slot as fallback content;
more than one content host with frame is invalid. Frame objects resolve with dom_id(), while null, false, empty, and
whitespace-only values disable the host.
The root owns the matching frame id. Use one <hw:drawer.content> for fallback content instead of adding a raw
<turbo-frame> with the same id.
view-transition mounts turbo--view-transition on the internal frame host for both automatic and explicit
drawer.content markup. It does nothing without frame; unsupported browsers keep the normal Turbo render. Enable it
on the drawer host rather than only on the response's <hw:frame-or-page> because Turbo preserves the existing host and
does not copy attributes from the response frame.
The drawer opens when the frame receives content. Per-link data-loading-template="#template-id" overrides the drawer's
loading_template slot. Use turbo_stream()->closeOverlay($request->overlayOrigin()) after a successful action to close
only that instance. Empty update/replace streams for its primary Frame remain supported and wait for exit motion.
One Drawer host can open several concrete instances. A link targeting its canonical Frame starts a new task; navigation
inside an open instance without an explicit Frame target reuses it. To close only the submitting instance with an empty
stream, use turbo_stream()->update($request->turboFrameId()), not the canonical host id. A global refresh can discard
other open drafts. See frame-backed overlay instances.
Requirements
- No external dependencies.
- Ships with
_composition.js,_focus_trap.js,_frame_overlay.js,_overlay.js,_overlay_stack.js,_overlay_presentation.js,_presence.js, and_top_layer.js; publishing thedrawercontroller publishes these helpers too.
Props
| Prop | Default | Description |
|---|---|---|
id |
auto | String or model root id; see stable component ids. |
direction |
down |
Physical up, right, down, or left; the direction does not mirror in RTL. |
side |
null |
Legacy alias for direction; top maps to up, bottom maps to down. |
size |
75vw/24rem for side drawers, auto for vertical drawers |
CSS length assigned to the drawer width or height variable. |
frame |
null |
String/object Turbo Frame id for layout-shared, server-loaded content. |
backdrop |
true |
Render the backdrop and click-outside target. |
motion |
default |
default follows CSS motion; none disables it. |
initial-focus |
auto |
auto, dialog, first-focusable, or none; invalid values use auto. |
lockScroll |
true |
Lock body scroll while open. |
closeOnEscape |
true |
Close when Escape is pressed. |
closeOnClickOutside |
true |
Close when the backdrop is clicked. |
viewTransition |
false |
Animate successive renders inside the frame host. |
aria-label |
null |
Authored accessible name routed to the dialog overlay. |
aria-labelledby |
null |
Authored accessible name reference routed to the dialog overlay. |
aria-description |
null |
Authored accessible description routed to the dialog overlay. |
aria-describedby |
null |
Authored accessible description reference routed to the dialog overlay. |
Components
| Component | Description |
|---|---|
drawer.trigger |
Button that toggles the drawer. |
drawer.content |
Overlay, backdrop and sliding popup wrapper. |
drawer.header |
Header region. |
drawer.title |
Drawer title. |
drawer.description |
Drawer description text. |
drawer.footer |
Footer actions region. |
drawer.close |
Button that closes the drawer. |
Future Enhancements
Swipe gestures, nested drawers and snap points are planned as separate enhancements after the base drawer behavior is stable.
Styling hooks
The component exposes stable data-slot hooks for preset and application CSS:
data-slot="drawer-overlay"data-slot="drawer-trigger"data-slot="drawer-backdrop"data-slot="drawer-popup"data-slot="drawer-content"data-slot="drawer-header"data-slot="drawer-title"data-slot="drawer-description"data-slot="drawer-footer"data-slot="drawer-close"data-slot="drawer"