drawer

A draggable panel that slides in from an edge of the screen.

PreviousNext
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';

import { ZardBadgeComponent } from '@/shared/components/badge';
import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import type { ZardDrawerPlacement } from '@/shared/components/drawer/drawer.variants';
import { ZardRadioGroupImports } from '@/shared/components/radio-group/radio-group.imports';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

import { injectIsMobile } from './support/is-mobile';

const DELIVERY_TIMES = [
  {
    value: 'asap',
    id: 'delivery-asap',
    label: 'Standard delivery',
    description: '25–35 min · Driver assigned now',
    badge: 'Fastest',
  },
  { value: '5-00', id: 'delivery-5-00', label: '5:00 PM – 5:15 PM', description: 'Prep starts at 4:45 PM' },
  { value: '5-30', id: 'delivery-5-30', label: '5:30 PM – 5:45 PM', description: `Good if you're heading home` },
  { value: '6-00', id: 'delivery-6-00', label: '6:00 PM – 6:15 PM', description: 'Most popular · High demand' },
  { value: '6-30', id: 'delivery-6-30', label: '6:30 PM – 6:45 PM', description: 'Last slot before kitchen closes' },
];

/** Content the service renders: the same list, so the pick is read back from the instance in `zOnOk`. */
@Component({
  selector: 'z-demo-drawer-preview-content',
  imports: [ZardBadgeComponent, ...ZardRadioGroupImports],
  template: `
    <z-radio-group [(value)]="deliveryTime" class="grid w-full gap-2">
      @for (time of times; track time.value) {
        <label
          [for]="'service-' + time.id"
          class="has-data-[state=checked]:bg-input/30 flex w-full items-center gap-3 rounded-2xl border p-4 select-none"
        >
          <span class="flex flex-1 flex-col gap-1 leading-snug">
            <span class="flex items-center gap-2 text-sm font-medium">
              {{ time.label }}
              @if (time.badge) {
                <z-badge zType="secondary">{{ time.badge }}</z-badge>
              }
            </span>
            <span class="text-muted-foreground text-sm">{{ time.description }}</span>
          </span>
          <z-radio [zId]="'service-' + time.id" [value]="time.value" />
        </label>
      }
    </z-radio-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerPreviewContentComponent {
  readonly times = DELIVERY_TIMES;
  readonly deliveryTime = signal<unknown>('asap');
}

@Component({
  selector: 'z-demo-drawer-preview',
  imports: [ZardBadgeComponent, ZardButtonComponent, ZardDrawerImports, ...ZardRadioGroupImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <button type="button" z-button zType="secondary" (click)="visible.set(true)">Open Drawer</button>

        <z-drawer [(zVisible)]="visible" [zPlacement]="placement()" [zHandle]="isMobile()">
          <z-drawer-header>
            <z-drawer-title>Pick a delivery time</z-drawer-title>
            <z-drawer-description>We'll prepare your order as soon as possible.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 overflow-y-auto p-4">
            <z-radio-group [(value)]="deliveryTime" class="grid w-full gap-2">
              @for (time of times; track time.value) {
                <label
                  [for]="time.id"
                  class="has-data-[state=checked]:bg-input/30 flex w-full items-center gap-3 rounded-2xl border p-4 select-none"
                >
                  <span class="flex flex-1 flex-col gap-1 leading-snug">
                    <span class="flex items-center gap-2 text-sm font-medium">
                      {{ time.label }}
                      @if (time.badge) {
                        <z-badge zType="secondary">{{ time.badge }}</z-badge>
                      }
                    </span>
                    <span class="text-muted-foreground text-sm">{{ time.description }}</span>
                  </span>
                  <z-radio [zId]="time.id" [value]="time.value" />
                </label>
              }
            </z-radio-group>
          </div>
          <z-drawer-footer>
            <button type="button" z-button (click)="visible.set(false)">Confirm Delivery Time</button>
            <button type="button" z-button zType="ghost" z-drawer-close>Cancel</button>
          </z-drawer-footer>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <button type="button" z-button zType="secondary" (click)="openDrawer()">Open Drawer</button>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerPreviewComponent {
  private readonly drawerService = inject(ZardDrawerService);
  private readonly isMobileViewport = injectIsMobile();

  readonly times = DELIVERY_TIMES;
  readonly visible = signal(false);
  readonly deliveryTime = signal<unknown>('asap');

  /** Bottom sheet where the screen is narrow, side panel where there is room. */
  readonly isMobile = computed(() => this.isMobileViewport());
  readonly placement = computed<ZardDrawerPlacement>(() => (this.isMobile() ? 'bottom' : 'right'));

  openDrawer() {
    this.drawerService.create({
      zTitle: 'Pick a delivery time',
      zDescription: `We'll prepare your order as soon as possible.`,
      zContent: ZardDemoDrawerPreviewContentComponent,
      zPlacement: this.placement(),
      zHandle: this.isMobile(),
      zOkText: 'Confirm Delivery Time',
      zCancelText: 'Cancel',
      zOnOk: instance => {
        console.log('Delivery time:', instance.deliveryTime());
      },
    });
  }
}

Installation

Copy
npx zard-cli@latest add drawer

Usage

import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
Copy
<button type="button" z-button zType="outline" (click)="visible.set(true)">Open</button>

<z-drawer [(zVisible)]="visible">
  <z-drawer-header>
    <z-drawer-title>Are you absolutely sure?</z-drawer-title>
    <z-drawer-description>This action cannot be undone.</z-drawer-description>
  </z-drawer-header>

  <div class="p-4"><!-- Content here --></div>

  <z-drawer-footer>
    <button type="button" z-button>Submit</button>
    <button type="button" z-button zType="outline" z-drawer-close>Cancel</button>
  </z-drawer-footer>
</z-drawer>
Copy

Composition

Use the following composition to build a drawer:

z-drawer
├── z-drawer-header
│   ├── z-drawer-title
│   └── z-drawer-description
├── (your content)
└── z-drawer-footer
    └── [z-drawer-close]
Copy

Examples

Custom Sizes

A vertical drawer sizes itself to its content and is capped at calc(100dvh - 6rem). A side drawer spans 75% of the viewport width, or 24rem on larger screens. Override either with class.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

/** Placeholder block the service renders as string content. */
const TALL_BOX = '<div class="bg-muted h-96 w-full rounded-2xl"></div>';
const FILL_BOX = '<div class="bg-muted min-h-40 w-full rounded-2xl"></div>';

@Component({
  selector: 'z-demo-drawer-custom-sizes',
  imports: [ZardButtonComponent, ZardDrawerImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <div class="flex flex-wrap gap-2">
          <button type="button" z-button zType="secondary" (click)="halfHeight.set(true)">Half height</button>
          <button type="button" z-button zType="secondary" (click)="wideSide.set(true)">Wide side</button>
        </div>

        <z-drawer [(zVisible)]="halfHeight" class="h-[50vh]">
          <z-drawer-header>
            <z-drawer-title>Half height</z-drawer-title>
            <z-drawer-description>The drawer keeps the height you give it.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 overflow-y-auto p-4">
            <div class="bg-muted h-96 w-full rounded-2xl"></div>
          </div>
        </z-drawer>

        <z-drawer [(zVisible)]="wideSide" zPlacement="right" class="sm:w-lg">
          <z-drawer-header>
            <z-drawer-title>Wide side</z-drawer-title>
            <z-drawer-description>A side drawer is 24rem wide until you widen it.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted size-full rounded-2xl"></div>
          </div>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <div class="flex flex-wrap gap-2">
          <button type="button" z-button zType="secondary" (click)="openHalfHeight()">Half height</button>
          <button type="button" z-button zType="secondary" (click)="openWideSide()">Wide side</button>
        </div>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerCustomSizesComponent {
  private readonly drawerService = inject(ZardDrawerService);

  readonly halfHeight = signal(false);
  readonly wideSide = signal(false);

  openHalfHeight() {
    this.drawerService.create({
      zTitle: 'Half height',
      zDescription: 'The drawer keeps the height you give it.',
      zCustomClasses: 'h-[50vh]',
      zContent: TALL_BOX,
      zHideFooter: true,
    });
  }

  openWideSide() {
    this.drawerService.create({
      zTitle: 'Wide side',
      zDescription: 'A side drawer is 24rem wide until you widen it.',
      zPlacement: 'right',
      zCustomClasses: 'sm:w-lg',
      zContent: FILL_BOX,
      zHideFooter: true,
    });
  }
}

Position

Use zPlacement to set the side of the drawer. Values are top, right, bottom and left.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import type { ZardDrawerPlacement } from '@/shared/components/drawer/drawer.variants';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

const PLACEMENTS: ZardDrawerPlacement[] = ['top', 'right', 'bottom', 'left'];

/** Placeholder block the service renders as string content. */
const BOX = '<div class="bg-muted min-h-40 w-full rounded-2xl"></div>';

@Component({
  selector: 'z-demo-drawer-position',
  imports: [ZardButtonComponent, ZardDrawerImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <div class="flex flex-wrap gap-2">
          @for (option of placements; track option) {
            <button type="button" z-button zType="secondary" class="capitalize" (click)="open(option)">
              {{ option }}
            </button>
          }
        </div>

        <z-drawer [(zVisible)]="visible" [zPlacement]="placement()">
          <z-drawer-header>
            <z-drawer-title>Move Goal</z-drawer-title>
            <z-drawer-description>Set your daily activity goal.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted size-full min-h-40 rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button z-drawer-close>Close</button>
          </z-drawer-footer>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <div class="flex flex-wrap gap-2">
          @for (option of placements; track option) {
            <button type="button" z-button zType="secondary" class="capitalize" (click)="openDrawer(option)">
              {{ option }}
            </button>
          }
        </div>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerPositionComponent {
  private readonly drawerService = inject(ZardDrawerService);

  readonly placements = PLACEMENTS;
  readonly visible = signal(false);
  readonly placement = signal<ZardDrawerPlacement>('bottom');

  open(placement: ZardDrawerPlacement) {
    this.placement.set(placement);
    this.visible.set(true);
  }

  openDrawer(placement: ZardDrawerPlacement) {
    this.drawerService.create({
      zTitle: 'Move Goal',
      zDescription: 'Set your daily activity goal.',
      zPlacement: placement,
      zContent: BOX,
      zOkText: null,
      zCancelText: 'Close',
    });
  }
}

Swipe Handle

Use zHandle to render a swipe handle.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

/** Placeholder block the service renders as string content. */
const BOX = '<div class="bg-muted h-80 w-full rounded-2xl"></div>';

@Component({
  selector: 'z-demo-drawer-swipe-handle',
  imports: [ZardButtonComponent, ZardDrawerImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <button type="button" z-button zType="secondary" (click)="visible.set(true)">Open Drawer</button>

        <z-drawer [(zVisible)]="visible" zHandle>
          <z-drawer-header>
            <z-drawer-title>Drawer</z-drawer-title>
            <z-drawer-description>Drawer with a swipe handle.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted h-80 w-full rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button z-drawer-close>Close</button>
          </z-drawer-footer>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <button type="button" z-button zType="secondary" (click)="openDrawer()">Open Drawer</button>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerSwipeHandleComponent {
  private readonly drawerService = inject(ZardDrawerService);

  readonly visible = signal(false);

  openDrawer() {
    this.drawerService.create({
      zTitle: 'Drawer',
      zDescription: 'Drawer with a swipe handle.',
      zHandle: true,
      zContent: BOX,
      zOkText: null,
      zCancelText: 'Close',
    });
  }
}

Nested

Open drawers from inside another drawer. Parent drawers stay mounted and stack behind the frontmost drawer.
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerRef } from '@/shared/components/drawer/drawer-ref';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { injectDrawerData, ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import type { ZardDrawerPlacement } from '@/shared/components/drawer/drawer.variants';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

import { injectIsMobile } from './support/is-mobile';

interface NestedDrawerData {
  level: number;
  placement: ZardDrawerPlacement;
  handle: boolean;
}

const LEVELS = [
  { title: 'Drawer', description: 'Open another drawer from the same direction.' },
  { title: 'Nested Drawer', description: 'The parent drawer stays mounted behind this one.' },
  { title: 'Third Drawer', description: 'Two drawers are stacked behind this one.' },
];

/** Content the service renders; the last level closes itself, the others open the next one. */
@Component({
  selector: 'z-demo-drawer-nested-content',
  imports: [ZardButtonComponent],
  template: `
    <div class="bg-muted size-full min-h-32 rounded-2xl"></div>
    <div class="flex flex-col gap-2">
      @if (data.level < levels.length) {
        <button type="button" z-button zType="outline" (click)="openNext()">Open Nested Drawer</button>
      } @else {
        <button type="button" z-button (click)="drawerRef.close()">Close</button>
      }
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerNestedContentComponent {
  private readonly drawerService = inject(ZardDrawerService);
  protected readonly drawerRef = inject(ZardDrawerRef);
  protected readonly data = injectDrawerData<NestedDrawerData>();
  protected readonly levels = LEVELS;

  openNext() {
    openNestedDrawer(this.drawerService, { ...this.data, level: this.data.level + 1 });
  }
}

function openNestedDrawer(drawerService: ZardDrawerService, data: NestedDrawerData) {
  const { title, description } = LEVELS[data.level - 1];

  drawerService.create({
    zTitle: title,
    zDescription: description,
    zContent: ZardDemoDrawerNestedContentComponent,
    zData: data,
    zPlacement: data.placement,
    zHandle: data.handle,
    zHideFooter: true,
  });
}

@Component({
  selector: 'z-demo-drawer-nested',
  imports: [ZardButtonComponent, ZardDrawerImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <button type="button" z-button zType="secondary" (click)="first.set(true)">Open Drawer</button>

        <z-drawer [(zVisible)]="first" [zPlacement]="placement()" [zHandle]="isMobile()">
          <z-drawer-header>
            <z-drawer-title>Drawer</z-drawer-title>
            <z-drawer-description>Open another drawer from the same direction.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted size-full min-h-32 rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button zType="outline" (click)="second.set(true)">Open Nested Drawer</button>
          </z-drawer-footer>
        </z-drawer>

        <z-drawer [(zVisible)]="second" [zPlacement]="placement()" [zHandle]="isMobile()">
          <z-drawer-header>
            <z-drawer-title>Nested Drawer</z-drawer-title>
            <z-drawer-description>The parent drawer stays mounted behind this one.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted size-full min-h-32 rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button zType="outline" (click)="third.set(true)">Open Third Drawer</button>
          </z-drawer-footer>
        </z-drawer>

        <z-drawer [(zVisible)]="third" [zPlacement]="placement()" [zHandle]="isMobile()">
          <z-drawer-header>
            <z-drawer-title>Third Drawer</z-drawer-title>
            <z-drawer-description>Two drawers are stacked behind this one.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted size-full min-h-32 rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button z-drawer-close>Close</button>
          </z-drawer-footer>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <button type="button" z-button zType="secondary" (click)="openDrawer()">Open Drawer</button>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerNestedComponent {
  private readonly drawerService = inject(ZardDrawerService);
  private readonly isMobileViewport = injectIsMobile();

  readonly first = signal(false);
  readonly second = signal(false);
  readonly third = signal(false);

  readonly isMobile = computed(() => this.isMobileViewport());
  readonly placement = computed<ZardDrawerPlacement>(() => (this.isMobile() ? 'bottom' : 'right'));

  openDrawer() {
    openNestedDrawer(this.drawerService, { level: 1, placement: this.placement(), handle: this.isMobile() });
  }
}

Non Modal

Set [zModal]="false" to allow interaction with the rest of the page while the drawer is open. A non-modal drawer keeps no mask, so an outside press does not dismiss it.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

/** Placeholder block the service renders as string content. */
const BOX = '<div class="bg-muted min-h-40 w-full rounded-2xl"></div>';

@Component({
  selector: 'z-demo-drawer-non-modal',
  imports: [ZardButtonComponent, ZardDrawerImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <button type="button" z-button zType="outline" (click)="visible.set(true)">Non Modal</button>

        <z-drawer [(zVisible)]="visible" zPlacement="right" [zModal]="false">
          <z-drawer-header>
            <z-drawer-title>Non Modal Drawer</z-drawer-title>
            <z-drawer-description>The page behind stays scrollable and clickable.</z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 p-4">
            <div class="bg-muted size-full rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button z-drawer-close>Close</button>
          </z-drawer-footer>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <button type="button" z-button zType="outline" (click)="openDrawer()">Non Modal</button>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerNonModalComponent {
  private readonly drawerService = inject(ZardDrawerService);

  readonly visible = signal(false);

  openDrawer() {
    this.drawerService.create({
      zTitle: 'Non Modal Drawer',
      zDescription: 'The page behind stays scrollable and clickable.',
      zPlacement: 'right',
      zMask: false,
      zContent: BOX,
      zOkText: null,
      zCancelText: 'Close',
    });
  }
}

Snap Points

Use zSnapPoints to snap a drawer to preset heights. Numbers between 0 and 1 represent fractions of the viewport. Numbers greater than 1 are treated as pixel values. String values support px and rem units. Snap points apply to vertical drawers. Track the active one with [(zSnapPoint)]; at the largest snap point the drawer gets a data-expanded attribute you can style against.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import type { ZardDrawerSnapPoint } from '@/shared/components/drawer/drawer.utils';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

const SNAP_POINTS: ZardDrawerSnapPoint[] = ['31rem', 1];

/** Placeholder block the service renders as string content. */
const BOX = '<div class="bg-muted h-80 w-full rounded-2xl"></div>';

@Component({
  selector: 'z-demo-drawer-snap-points',
  imports: [ZardButtonComponent, ZardDrawerImports, ZardTabsImports],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <button type="button" z-button zType="outline" (click)="visible.set(true)">Open Snap Drawer</button>

        <z-drawer [(zVisible)]="visible" [zSnapPoints]="snapPoints" [(zSnapPoint)]="snapPoint" zHandle>
          <z-drawer-header>
            <z-drawer-title>Snap points</z-drawer-title>
            <z-drawer-description>
              Drag the drawer to snap between a compact peek and a near full-height view.
            </z-drawer-description>
          </z-drawer-header>
          <div class="flex-1 touch-pan-y overflow-y-auto p-4">
            <div class="bg-muted h-80 w-full rounded-2xl"></div>
          </div>
          <z-drawer-footer>
            <button type="button" z-button z-drawer-close>Close</button>
          </z-drawer-footer>
        </z-drawer>
      </z-tab>

      <z-tab label="Service">
        <button type="button" z-button zType="outline" (click)="openDrawer()">Open Snap Drawer</button>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerSnapPointsComponent {
  private readonly drawerService = inject(ZardDrawerService);

  readonly snapPoints = SNAP_POINTS;
  readonly visible = signal(false);
  readonly snapPoint = signal<ZardDrawerSnapPoint | undefined>('31rem');

  openDrawer() {
    this.drawerService.create({
      zTitle: 'Snap points',
      zDescription: 'Drag the drawer to snap between a compact peek and a near full-height view.',
      zSnapPoints: SNAP_POINTS,
      zSnapPoint: '31rem',
      zHandle: true,
      zContent: BOX,
      zOkText: null,
      zCancelText: 'Close',
    });
  }
}

Responsive

You can combine the Dialog and Drawer components to create a responsive dialog. This renders a Dialog on desktop and a Drawer on mobile.
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';

import { ZardButtonComponent } from '@/shared/components/button';
import { ZardDialogImports } from '@/shared/components/dialog/dialog.imports';
import { ZardDialogService } from '@/shared/components/dialog/dialog.service';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardDrawerService } from '@/shared/components/drawer/drawer.service';
import { ZardInputComponent } from '@/shared/components/input';
import { ZardTabsImports } from '@/shared/components/tabs/tabs.imports';

import { injectIsMobile } from './support/is-mobile';

@Component({
  selector: 'z-demo-drawer-profile-form',
  imports: [ZardButtonComponent, ZardInputComponent],
  template: `
    <form class="grid items-start gap-6" (submit)="$event.preventDefault()">
      <div class="grid gap-3">
        <label for="drawer-demo-email" class="text-sm leading-none font-medium select-none">Email</label>
        <input z-input id="drawer-demo-email" type="email" value="shadcn@example.com" />
      </div>
      <div class="grid gap-3">
        <label for="drawer-demo-username" class="text-sm leading-none font-medium select-none">Username</label>
        <input z-input id="drawer-demo-username" value="@shadcn" />
      </div>
      <button type="submit" z-button>Save changes</button>
    </form>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerProfileFormComponent {}

/** Same content, two surfaces: a dialog where there is room, a drawer where there is not. */
@Component({
  selector: 'z-demo-drawer-responsive',
  imports: [
    ZardButtonComponent,
    ZardDialogImports,
    ZardDrawerImports,
    ZardTabsImports,
    ZardDemoDrawerProfileFormComponent,
  ],
  template: `
    <z-tab-group>
      <z-tab label="Template">
        <button type="button" z-button zType="outline" (click)="visible.set(true)">Edit Profile</button>

        @if (isMobile()) {
          <z-drawer [(zVisible)]="visible">
            <z-drawer-header>
              <z-drawer-title>Edit profile</z-drawer-title>
              <z-drawer-description>
                Make changes to your profile here. Click save when you're done.
              </z-drawer-description>
            </z-drawer-header>
            <div class="p-4">
              <z-demo-drawer-profile-form />
            </div>
          </z-drawer>
        } @else {
          <z-dialog [(zVisible)]="visible">
            <z-dialog-header>
              <z-dialog-title>Edit profile</z-dialog-title>
              <z-dialog-description>
                Make changes to your profile here. Click save when you're done.
              </z-dialog-description>
            </z-dialog-header>
            <z-demo-drawer-profile-form />
          </z-dialog>
        }
      </z-tab>

      <z-tab label="Service">
        <button type="button" z-button zType="outline" (click)="open()">Edit Profile</button>
      </z-tab>
    </z-tab-group>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerResponsiveComponent {
  private readonly dialogService = inject(ZardDialogService);
  private readonly drawerService = inject(ZardDrawerService);
  private readonly isMobileViewport = injectIsMobile();

  readonly visible = signal(false);
  readonly isMobile = this.isMobileViewport;

  open() {
    if (this.isMobile()) {
      this.drawerService.create({
        zTitle: 'Edit profile',
        zDescription: `Make changes to your profile here. Click save when you're done.`,
        zContent: ZardDemoDrawerProfileFormComponent,
        zHideFooter: true,
      });
      return;
    }

    this.dialogService.create({
      zTitle: 'Edit profile',
      zDescription: `Make changes to your profile here. Click save when you're done.`,
      zContent: ZardDemoDrawerProfileFormComponent,
      zHideFooter: true,
    });
  }
}

RTL

To enable RTL support in zard/ui, see the RTL configuration guide.
// You will notice this example is rendered inside a wrapper that sets the dir and data-lang attributes, and
// reads its text from a translations helper. This is because this site is not RTL by default.
// In your application you won't need either: set dir="rtl" on <html> (or use the CDK Dir directive on a subtree)
// and write the text of your own language. See the RTL guide: https://zardui.com/docs/rtl

import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';

import { ZardBadgeComponent } from '@/shared/components/badge/badge.component';
import { ZardButtonComponent } from '@/shared/components/button/button.component';
import { ZardDrawerImports } from '@/shared/components/drawer/drawer.imports';
import { ZardRadioGroupImports } from '@/shared/components/radio-group/radio-group.imports';
import { injectRtlTranslation, type ZardRtlTranslations } from '@/shared/demo-utils/rtl-translation';

interface DrawerRtlStrings {
  trigger: string;
  title: string;
  description: string;
  confirm: string;
  cancel: string;
  asapLabel: string;
  asapDescription: string;
  asapBadge: string;
  slot500Label: string;
  slot500Description: string;
  slot530Label: string;
  slot530Description: string;
  slot600Label: string;
  slot600Description: string;
}

const translations: ZardRtlTranslations<DrawerRtlStrings> = {
  en: {
    dir: 'ltr',
    values: {
      trigger: 'Open Drawer',
      title: 'Pick a delivery time',
      description: "We'll prepare your order as soon as possible.",
      confirm: 'Confirm Delivery Time',
      cancel: 'Cancel',
      asapLabel: 'Standard delivery',
      asapDescription: '25–35 min · Driver assigned now',
      asapBadge: 'Fastest',
      slot500Label: '5:00 PM – 5:15 PM',
      slot500Description: 'Prep starts at 4:45 PM',
      slot530Label: '5:30 PM – 5:45 PM',
      slot530Description: "Good if you're heading home",
      slot600Label: '6:00 PM – 6:15 PM',
      slot600Description: 'Most popular · High demand',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      trigger: 'فتح الدرج',
      title: 'اختر وقت التوصيل',
      description: 'سنجهز طلبك في أقرب وقت ممكن.',
      confirm: 'تأكيد وقت التوصيل',
      cancel: 'إلغاء',
      asapLabel: 'توصيل قياسي',
      asapDescription: '25–35 دقيقة · تم تعيين السائق الآن',
      asapBadge: 'الأسرع',
      slot500Label: '5:00 م – 5:15 م',
      slot500Description: 'يبدأ التحضير في 4:45 م',
      slot530Label: '5:30 م – 5:45 م',
      slot530Description: 'مناسب إذا كنت في الطريق إلى المنزل',
      slot600Label: '6:00 م – 6:15 م',
      slot600Description: 'الأكثر شيوعًا · طلب مرتفع',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      trigger: 'פתח מגירה',
      title: 'בחר זמן משלוח',
      description: 'נכין את ההזמנה שלך בהקדם האפשרי.',
      confirm: 'אשר זמן משלוח',
      cancel: 'בטל',
      asapLabel: 'משלוח רגיל',
      asapDescription: '25–35 דק׳ · נהג הוקצה כעת',
      asapBadge: 'הכי מהיר',
      slot500Label: '17:00 – 17:15',
      slot500Description: 'ההכנה מתחילה ב-16:45',
      slot530Label: '17:30 – 17:45',
      slot530Description: 'מתאים אם אתה בדרך הביתה',
      slot600Label: '18:00 – 18:15',
      slot600Description: 'הפופולרי ביותר · ביקוש גבוה',
    },
  },
};

@Component({
  selector: 'z-demo-drawer-rtl',
  imports: [ZardBadgeComponent, ZardButtonComponent, ZardDrawerImports, ZardRadioGroupImports],
  template: `
    @let t = i18n.t();
    <button type="button" z-button zType="secondary" (click)="visible.set(true)">{{ t.trigger }}</button>

    <!-- zPlacement and the swipe-to-close axis stay physical, whatever the direction. -->
    <z-drawer [(zVisible)]="visible" zPlacement="right">
      <z-drawer-header>
        <z-drawer-title>{{ t.title }}</z-drawer-title>
        <z-drawer-description>{{ t.description }}</z-drawer-description>
      </z-drawer-header>

      <div class="flex-1 overflow-y-auto p-4">
        <z-radio-group [(value)]="deliveryTime" class="gap-2">
          @for (slot of slots(); track slot.value) {
            <label
              [attr.for]="'drawer-rtl-' + slot.value"
              class="has-[[data-state=checked]]:border-primary flex items-start gap-3 rounded-lg border p-3 text-sm"
            >
              <z-radio [zId]="'drawer-rtl-' + slot.value" [value]="slot.value" />
              <span class="grid flex-1 gap-1">
                <span class="flex items-center gap-2 font-medium">
                  {{ slot.label }}
                  @if (slot.badge) {
                    <z-badge zType="secondary">{{ slot.badge }}</z-badge>
                  }
                </span>
                <span class="text-muted-foreground text-xs">{{ slot.description }}</span>
              </span>
            </label>
          }
        </z-radio-group>
      </div>

      <z-drawer-footer>
        <button type="button" z-button (click)="visible.set(false)">{{ t.confirm }}</button>
        <button type="button" z-button zType="outline" z-drawer-close>{{ t.cancel }}</button>
      </z-drawer-footer>
    </z-drawer>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDrawerRtlComponent {
  protected readonly i18n = injectRtlTranslation(translations);

  protected readonly visible = signal(false);
  protected readonly deliveryTime = signal<string>('asap');

  protected readonly slots = computed(() => {
    const t = this.i18n.t();
    return [
      { value: 'asap', label: t.asapLabel, description: t.asapDescription, badge: t.asapBadge },
      { value: '5-00', label: t.slot500Label, description: t.slot500Description, badge: '' },
      { value: '5-30', label: t.slot530Label, description: t.slot530Description, badge: '' },
      { value: '6-00', label: t.slot600Label, description: t.slot600Description, badge: '' },
    ];
  });
}

API Reference

z-drawer

Declarative drawer root, tunable via --z-drawer-inset and --z-drawer-bleed.

Prop
[zVisible]

Two-way bindable open state

Type
boolean
Default
false
[zPlacement]

Edge it slides from; also sets the swipe axis

Type
'top' | 'right' | 'bottom' | 'left'
Default
'bottom'
[zSnapPoints]

Rest sizes: 0–1 viewport fraction, else px or CSS

Type
(number | string)[]
Default
—
[zSnapPoint]

Two-way bindable active snap point

Type
number | string
Default
—
[zDismissible]

Swipe, mask and Escape can close it

Type
boolean
Default
true
[zHandle]

Shows the swipe handle

Type
boolean
Default
false
[zModal]

Shows the mask and blocks the page

Type
boolean
Default
true
[class]

Custom CSS classes

Type
ClassValue
Default
—
(zAfterOpen)

Emits once the drawer is attached

Type
EventEmitter<void>
Default
—
(zAfterClose)

Emits after the exit animation

Type
EventEmitter<void>
Default
—

z-drawer-header

Top slot for the title and description.

Prop
[class]

Custom CSS classes

Type
ClassValue
Default
—

z-drawer-footer

Bottom slot, usually for actions.

Prop
[class]

Custom CSS classes

Type
ClassValue
Default
—

z-drawer-title

Drawer title, wired to aria-labelledby.

Prop
[zTitle]

Title text or template

Type
string | TemplateRef<void>
Default
—
[class]

Custom CSS classes

Type
ClassValue
Default
—

z-drawer-description

Supporting text, wired to aria-describedby.

Prop
[zDescription]

Description text or template

Type
string | TemplateRef<void>
Default
—
[class]

Custom CSS classes

Type
ClassValue
Default
—

[z-drawer-close]

Closes the enclosing drawer.

ZardDrawerOptions

Options for ZardDrawerService.create().

Prop
[zTitle]

Title text or template

Type
string | TemplateRef<void>
Default
—
[zDescription]

Description text or template

Type
string | TemplateRef<void>
Default
—
[zContent]

Content component, template or HTML

Type
string | TemplateRef<T> | Type<T>
Default
—
[zPlacement]

Edge it slides from

Type
'top' | 'right' | 'bottom' | 'left'
Default
'bottom'
[zSnapPoints]

Rest sizes

Type
(number | string)[]
Default
—
[zSnapPoint]

Initial snap point

Type
number | string
Default
—
[zDismissible]

Swipe, mask and Escape can close it

Type
boolean
Default
true
[zHandle]

Shows the swipe handle

Type
boolean
Default
false
[zMask]

Shows the backdrop and blocks the page

Type
boolean
Default
true
[zMaskClosable]

Outside click closes it. Requires zDismissible

Type
boolean
Default
true
[zClosable]

Shows the close button

Type
boolean
Default
true
[zDuration]

Exit animation duration in ms

Type
number
Default
450
[zOkText]

OK button text, null hides it

Type
string | null
Default
'OK'
[zCancelText]

Cancel button text, null hides it

Type
string | null
Default
'Cancel'
[zOkIcon]

OK button icon name or SVG

Type
string
Default
—
[zCancelIcon]

Cancel button icon name or SVG

Type
string
Default
—
[zOkDestructive]

Destructive OK button

Type
boolean
Default
false
[zOkDisabled]

Disables the OK button

Type
boolean
Default
false
[zHideFooter]

Hides the action footer

Type
boolean
Default
false
[zCustomClasses]

Custom CSS classes

Type
ClassValue
Default
—
[zOnOk]

OK click handler

Type
EventEmitter<T> | OnClickCallback<T>
Default
—
[zOnCancel]

Cancel click handler

Type
EventEmitter<T> | OnClickCallback<T>
Default
—
[zData]

Data for the content component

Type
object
Default
—
[zViewContainerRef]

View container for the content

Type
ViewContainerRef
Default
—

ZardDrawerRef

Handle returned by ZardDrawerService.create().

Prop
[close]

Closes the drawer with an optional result

Type
(result?: R) => void
Default
—
[isClosing]

True once closing starts

Type
Signal<boolean>
Default
false
[result]

Result passed to close()

Type
Signal<R | undefined>
Default
—
[componentInstance]

Rendered content component instance

Type
Signal<T | null>
Default
null
github iconwhatsapp icondiscord iconX icon

Made with ❤ in Brazil. Open source and available on GitHub .