Drawer
Display a content that slides in from the side of the screen.
Usage
Use standalone.
<Drawer {...props}>Content</Drawer>Anatomy
The class attribute values represent part names. Other attributes represent their corresponding props.
<dialog class="whole" {...rest} {style}>
{children}
</dialog>Props
| Name | Type | Default | Description |
|---|---|---|---|
children* | Snippet | - | Drawer content; receives the variant as its argument |
open | boolean | false | Bindable open state |
position | Position | "left" | Specifies where to display the Drawer |
size | string | "auto" | Specifies a valid CSS value for the Drawer width or height |
duration | number | 200 | Animation duration in milliseconds |
cssvar | Record | - | Renames the published animation-timing custom property; cssvar.duration makes the Drawer read --svs-duration from a caller-named token |
closable | boolean | true | Whether light dismiss is enabled; false creates a forced-action modal with no light-dismiss or Escape |
ariaLabel | string | - | Accessible label for the dialog |
element | HTMLDialogElement | - | Bindable root element |
styling | SVSClass | - | Styling override |
variant | SVSVariant | NEUTRAL | Drawer variant |
* required. Other HTMLDialogAttributes are passed to <dialog> via rest props; class is merged onto the root.
If size is omitted, auto is used. It's recommended to specify the size explicitly, since the CSS property interpolate-size: allow-keywords;, which is not yet supported by some browsers, is applied when using auto.
Drawer is a native modal <dialog> opened with showModal(): focus is trapped and background content is inert while open, and page scroll is locked with :root:has(dialog[open]).
Styling
In this component, margin and padding cannot be used for the whole part. To learn more, see Styling.
Variant Management
No automatic switching.
Default Class Name
svs-drawer
Behavior
Drawer is modal: focus is trapped and background siblings are inert while open by native dialog behavior. closable=false creates a forced-action modal (no light-dismiss/Escape).
Open/close animation timing is published as --svs-duration for caller CSS; cssvar.duration renames it (caller then owns reduced-motion for that token).
Accessibility
ARIA Roles and Attributes
The component applies these automatically:
- Dialog (
whole<dialog>):aria-labelfrom theariaLabelprop.
Provide an accessible name yourself because there is no built-in visible label. Pass ariaLabel, or pass aria-labelledby through the rest props. The managed aria-label attribute is omitted from DrawerProps and cannot be passed as aria-label.
Standards Basis
Drawer is built on a native <dialog> opened with showModal(), so keyboard and assistive-technology support follows the browser standard for modal dialogs. See the Concepts standards-first guidance for the library's approach. When closable is false, the component prevents the native Escape light-dismiss.
Exports
Types
type Position = "top" | "right" | "bottom" | "left";
type DrawerCssVar = "duration";
interface DrawerProps extends Omit<HTMLDialogAttributes, "children" | "style" | "aria-label"> {
children: Snippet<[string]>; // Snippet<[variant]>
open?: boolean; // bindable (false)
position?: Position; // ("left")
size?: string; // ("auto")
duration?: number; // (200)
cssvar?: Partial<Record<DrawerCssVar, string>>;
closable?: boolean; // (true)
ariaLabel?: string;
element?: HTMLDialogElement; // bindable
styling?: SVSClass;
variant?: SVSVariant; // (VARIANT.NEUTRAL)
// other HTMLDialogAttributes are passed to <dialog> via ...rest; `class` is merged onto root
// style is component-owned (omitted)
}
type DrawerReqdProps = "children";
type DrawerBindProps = "open" | "element";Others
No additional exports are available.
Examples
The example code uses Tailwind CSS along with SVSClass.