Drawer
A panel at the edge of the screen that a swipe dismisses — or moves between its snap points. In the look of the app's style.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal, ScDrawerProvider, ScDrawerTitle, ScDrawerTrigger, ScField, ScFieldGroup, ScInput, ScLabel, ScSelectOnFocus,} from '@semantic-components/ui';
@Component({ selector: 'app-drawer-usage-demo', imports: [ ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal, ScDrawerProvider, ScDrawerTitle, ScDrawerTrigger, ScField, ScFieldGroup, ScInput, ScLabel, ScSelectOnFocus, ], template: ` <div scDrawerProvider [(open)]="open"> <button scButton scDrawerTrigger variant="outline">Edit profile</button> <ng-template scDrawerPortal> <div scDrawer> <div scDrawerHandle></div> <div scDrawerHeader> <h2 scDrawerTitle>Edit profile</h2> <p scDrawerDescription> Make changes to your profile here. Click save when you're done. </p> </div> <div scFieldGroup class="p-4"> <div scField> <label scLabel>Email</label> <input cdkFocusInitial scSelectOnFocus="program" scInput value="[email protected]" /> </div> <div scField> <label scLabel>Username</label> <input scInput value="@shadcn" /> </div> </div> <div scDrawerFooter> <button scButton (click)="open.set(false)">Save changes</button> <button scDrawerClose>Cancel</button> </div> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class DrawerUsageDemo { private readonly open = signal(false);}Anatomy
Every part is a directive on your element; the trigger, the title, the content and the close buttons are yours.
import { ScDrawerProvider, ScDrawerTrigger, ScDrawerPortal, ScDrawer, ScDrawerHandle, ScDrawerHeader, ScDrawerTitle, ScDrawerDescription, ScDrawerFooter, ScDrawerClose,} from '@semantic-components/ui';<div scDrawerProvider swipeDirection="…"> <button scButton scDrawerTrigger>…</button> <ng-template scDrawerPortal> <div scDrawer> <div scDrawerHandle></div> <div scDrawerHeader> <h2 scDrawerTitle>…</h2> <p scDrawerDescription>…</p> </div> … <div scDrawerFooter> <button scDrawerClose>…</button> </div> </div> </ng-template></div>Accessibility
- A dialog (role="dialog", aria-modal when modal), named by its title and described by its description.
- Focus moves into it and, unless [modal]="false", stays there; closing gives it back to the trigger. Escape closes it, as does a press outside (unless disablePointerDismissal).
- Swiping is for the pointer only: a keyboard closes it with Escape or its close button. A handle on a div is hidden from screen readers; on a button, named by you, it moves to the next snap point.
Examples
Sides
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal,Swipe handle
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal,Snap points
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal,Nested
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal,Non-modal
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader, ScDrawerPortal, ScDrawerProvider,Responsive
import { DOCUMENT } from '@angular/common';import { Component, DestroyRef, ViewEncapsulation, inject, signal,} from '@angular/core';import { ScButton,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScButton, ScDrawer, ScDrawerClose, ScDrawerDescription, ScDrawerFooter, ScDrawerHandle, ScDrawerHeader,API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScDrawerProvider | div[scDrawerProvider], span[scDrawerProvider] | [(open)], swipeDirection ('down', 'up', 'left', 'right', 'inline-start', 'inline-end'), snapPoints and [(snapPoint)], modal (true, 'trap-focus', false), disablePointerDismissal. |
ScDrawerTrigger | button[scDrawerTrigger] | Opens and closes it, on any button (aria-haspopup, aria-expanded). |
ScDrawerPortal, ScDrawer | ng-template[…], div[scDrawer] | The content, rendered while open; the panel (role="dialog"), named and described, sliding from its edge and following a swipe. |
ScDrawerHandle | div[scDrawerHandle], button[scDrawerHandle] | The bar to drag it by. On a button (named): the next snap point. |
ScDrawerHeader, ScDrawerTitle, ScDrawerDescription, ScDrawerFooter | div[…], h2[…], p[…], div[…] | Its title and description at the top; its actions at the bottom. |
ScDrawerClose | button[scDrawerClose] | Closes it: the style's button (outline by default); variant and size of your choice. |