date picker

A button that opens a calendar in a popover to pick one date, several dates, or a date range.

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

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';

import { ZardDatePickerComponent } from '../date-picker.component';

@Component({
  selector: 'z-demo-date-picker-preview',
  imports: [ZardDatePickerComponent],
  template: `
    <z-date-picker class="mx-auto" [(value)]="selectedDate" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerPreviewComponent {
  readonly selectedDate = signal<CalendarValue>(null);
}

Installation

Copy
npx zard-cli@latest add date-picker

Usage

import { ZardDatePickerComponent } from '@/shared/components/date-picker/date-picker.component';
Copy
<z-date-picker zPlaceholder="Pick a date"></z-date-picker>
Copy

Examples

Basic

Pair it with a <div z-field> label through zId, and use zIcon="none" to drop the trailing chevron.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';

import { ZardDatePickerComponent } from '../date-picker.component';

@Component({
  selector: 'z-demo-date-picker-basic',
  imports: [ZardDatePickerComponent, ZardFieldImports],
  template: `
    <div z-field class="mx-auto w-44">
      <label z-field-label for="date-picker-basic">Date</label>
      <z-date-picker zId="date-picker-basic" zIcon="none" [(value)]="selectedDate" />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerBasicComponent {
  readonly selectedDate = signal<CalendarValue>(null);
}

Date Of Birth

Use zCaptionLayout="dropdown" with minDate/maxDate to jump across decades in two clicks.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';

import { ZardDatePickerComponent } from '../date-picker.component';

@Component({
  selector: 'z-demo-date-picker-date-of-birth',
  imports: [ZardDatePickerComponent, ZardFieldImports],
  template: `
    <div z-field class="mx-auto w-44">
      <label z-field-label for="date-picker-date-of-birth">Date of birth</label>
      <z-date-picker
        zId="date-picker-date-of-birth"
        zIcon="none"
        zCaptionLayout="dropdown"
        zPlaceholder="Select date"
        [minDate]="minDate"
        [maxDate]="maxDate"
        [(value)]="selectedDate"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerDateOfBirthComponent {
  readonly selectedDate = signal<CalendarValue>(null);

  /** The bounds are what widen the year dropdown — without them it spans today ± 10 years. */
  readonly minDate = new Date(1900, 0, 1);
  readonly maxDate = new Date();
}

Range

Use zMode="range" to pick a start and an end date — the popover only closes once both ends are set.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';

import { ZardDatePickerComponent } from '../date-picker.component';

const currentYear = new Date().getFullYear();

@Component({
  selector: 'z-demo-date-picker-range',
  imports: [ZardDatePickerComponent, ZardFieldImports],
  template: `
    <div z-field class="mx-auto w-60">
      <label z-field-label for="date-picker-range">Date range</label>
      <z-date-picker
        zId="date-picker-range"
        zMode="range"
        zIcon="calendar"
        zFormat="MMM dd, y"
        [zNumberOfMonths]="2"
        [(value)]="selectedRange"
      />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerRangeComponent {
  readonly selectedRange = signal<CalendarValue>([new Date(currentYear, 0, 20), new Date(currentYear, 1, 9)]);
}

Time Picker

Put the picker next to a type="time" input to collect a date and a time.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';
import { ZardInputComponent } from '@/shared/components/input/input.component';

import { ZardDatePickerComponent } from '../date-picker.component';

@Component({
  selector: 'z-demo-date-picker-time-picker',
  imports: [ZardDatePickerComponent, ZardFieldImports, ZardInputComponent],
  template: `
    <!-- A fixed width, not max-w-*: the field group is w-full, so it has nothing to resolve against. -->
    <div z-field-group class="mx-auto w-xs flex-row">
      <!-- The width goes on the field: it forces w-full onto whatever it wraps. -->
      <div z-field class="w-40">
        <label z-field-label for="date-picker-time-picker-date">Date</label>
        <z-date-picker
          zId="date-picker-time-picker-date"
          zCaptionLayout="dropdown"
          zPlaceholder="Select date"
          zFormat="MMM d, yyyy"
          [(value)]="selectedDate"
        />
      </div>

      <div z-field class="w-32">
        <label z-field-label for="date-picker-time">Time</label>
        <input
          z-input
          id="date-picker-time"
          type="time"
          step="1"
          value="10:30:00"
          class="appearance-none [&::-webkit-calendar-picker-indicator]:hidden"
        />
      </div>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerTimePickerComponent {
  readonly selectedDate = signal<CalendarValue>(null);
}

Input

Compose z-input-group, z-popover and z-calendar when the date should also be typeable — arrow down opens the calendar.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideCalendar } from '@ng-icons/lucide';

import { ZardCalendarComponent } from '@/shared/components/calendar/calendar.component';
import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';
import { ZardInputComponent } from '@/shared/components/input/input.component';
import { ZardInputGroupImports } from '@/shared/components/input-group/input-group.imports';
import { ZardPopoverComponent, ZardPopoverDirective } from '@/shared/components/popover';

const MONTHS = [
  'january',
  'february',
  'march',
  'april',
  'may',
  'june',
  'july',
  'august',
  'september',
  'october',
  'november',
  'december',
];

function formatDate(date: Date | null): string {
  if (!date) {
    return '';
  }

  return date.toLocaleDateString('en-US', { day: '2-digit', month: 'long', year: 'numeric' });
}

/**
 * Parses the one format this demo documents — `June 01, 2025` — as a local date.
 * `new Date(value)` is not an option: it reads date-only ISO strings as UTC, so west of UTC the
 * calendar would land a day earlier than what was typed.
 */
function parseDate(value: string): Date | null {
  const match = /^\s*([a-zA-Z]+)\s+(\d{1,2}),?\s+(\d{4})\s*$/.exec(value);
  if (!match) {
    return null;
  }

  const month = MONTHS.indexOf(match[1].toLowerCase());
  const day = Number(match[2]);
  const year = Number(match[3]);

  if (month < 0) {
    return null;
  }

  // Set the three parts at once on a neutral date: `new Date(year, …)` would remap any year below
  // 100 into the 1900s, and normalize against the wrong year's leap day on the way.
  const date = new Date(2000, 0, 1);
  date.setFullYear(year, month, day);

  // Rejects overflow like "February 31, 2025", which setFullYear rolls over instead of refusing.
  return date.getFullYear() === year && date.getMonth() === month && date.getDate() === day ? date : null;
}

@Component({
  selector: 'z-demo-date-picker-input',
  imports: [
    NgIcon,
    ZardCalendarComponent,
    ZardFieldImports,
    ZardInputComponent,
    ZardInputGroupImports,
    ZardPopoverComponent,
    ZardPopoverDirective,
  ],
  template: `
    <div z-field class="mx-auto w-52">
      <label z-field-label for="date-picker-input">Subscription date</label>
      <z-input-group>
        <input
          z-input
          id="date-picker-input"
          placeholder="June 01, 2025"
          [value]="inputValue()"
          (input)="onInput($event)"
          (keydown)="onKeydown($event)"
        />
        <z-input-group-addon zAlign="inline-end">
          <button
            type="button"
            z-input-group-button
            aria-label="Select date"
            zPopover
            zAlign="end"
            [zContent]="calendarTemplate"
            [zVisible]="isOpen()"
            [zAlignOffset]="-8"
            [zSideOffset]="10"
            (zVisibleChange)="isOpen.set($event)"
          >
            <ng-icon name="lucideCalendar" class="size-4!" />
          </button>
        </z-input-group-addon>
      </z-input-group>
    </div>

    <ng-template #calendarTemplate>
      <z-popover aria-label="Choose date" class="w-auto overflow-hidden p-0">
        <z-calendar [value]="selectedDate()" (valueChange)="onSelect($event)" />
      </z-popover>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  viewProviders: [provideIcons({ lucideCalendar })],
})
export class ZardDemoDatePickerInputComponent {
  readonly selectedDate = signal<Date | null>(new Date(2025, 5, 1));
  readonly inputValue = signal(formatDate(new Date(2025, 5, 1)));
  readonly isOpen = signal(false);

  onInput(event: Event): void {
    const typed = (event.target as HTMLInputElement).value;
    this.inputValue.set(typed);

    const parsed = parseDate(typed);
    if (parsed) {
      this.selectedDate.set(parsed);
    }
  }

  /** Arrow down opens the calendar, the way a native date input does. */
  onKeydown(event: KeyboardEvent): void {
    if (event.key === 'ArrowDown') {
      event.preventDefault();
      this.isOpen.set(true);
    }
  }

  onSelect(value: CalendarValue): void {
    const date = Array.isArray(value) ? (value[0] ?? null) : value;
    this.selectedDate.set(date);
    this.inputValue.set(formatDate(date));
    this.isOpen.set(false);
  }
}

Sizes

zSize follows the button scale, so a picker lines up with the inputs around it.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';

import { ZardDatePickerComponent } from '../date-picker.component';

@Component({
  selector: 'z-demo-date-picker-sizes',
  imports: [ZardDatePickerComponent, ZardFieldImports],
  template: `
    <div z-field-group class="mx-auto w-60">
      <div z-field>
        <label z-field-label for="date-picker-size-xs">Extra small</label>
        <z-date-picker zId="date-picker-size-xs" zSize="xs" [(value)]="selectedDate" />
      </div>

      <div z-field>
        <label z-field-label for="date-picker-size-sm">Small</label>
        <z-date-picker zId="date-picker-size-sm" zSize="sm" [(value)]="selectedDate" />
      </div>

      <div z-field>
        <label z-field-label for="date-picker-size-default">Default</label>
        <z-date-picker zId="date-picker-size-default" [(value)]="selectedDate" />
      </div>

      <div z-field>
        <label z-field-label for="date-picker-size-lg">Large</label>
        <z-date-picker zId="date-picker-size-lg" zSize="lg" [(value)]="selectedDate" />
      </div>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerSizesComponent {
  readonly selectedDate = signal<CalendarValue>(new Date());
}

Formats

zFormat takes any Angular DatePipe pattern.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardFieldImports } from '@/shared/components/field/field.imports';

import { ZardDatePickerComponent } from '../date-picker.component';

@Component({
  selector: 'z-demo-date-picker-formats',
  imports: [ZardDatePickerComponent, ZardFieldImports],
  template: `
    <div z-field-group class="mx-auto w-60">
      <div z-field>
        <label z-field-label for="date-picker-format-default">MMMM d, yyyy</label>
        <z-date-picker zId="date-picker-format-default" [(value)]="selectedDate" />
      </div>

      <div z-field>
        <label z-field-label for="date-picker-format-us">MM/dd/yyyy</label>
        <z-date-picker zId="date-picker-format-us" zFormat="MM/dd/yyyy" [(value)]="selectedDate" />
      </div>

      <div z-field>
        <label z-field-label for="date-picker-format-iso">yyyy-MM-dd</label>
        <z-date-picker zId="date-picker-format-iso" zFormat="yyyy-MM-dd" [(value)]="selectedDate" />
      </div>

      <div z-field>
        <label z-field-label for="date-picker-format-day-name">EEE, MMMM d</label>
        <z-date-picker zId="date-picker-format-day-name" zFormat="EEE, MMMM d" [(value)]="selectedDate" />
      </div>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerFormatsComponent {
  /** Shared on purpose — every picker shows the same date under a different format. */
  readonly selectedDate = signal<CalendarValue>(new Date());
}

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, signal } from '@angular/core';

import type { CalendarValue } from '@/shared/components/calendar/calendar.types';
import { ZardDatePickerComponent } from '@/shared/components/date-picker/date-picker.component';
import { injectRtlTranslation, type ZardRtlTranslations } from '@/shared/demo-utils/rtl-translation';

const translations: ZardRtlTranslations<{ label: string; placeholder: string; locale: string }> = {
  en: {
    dir: 'ltr',
    values: {
      label: 'Date of birth',
      placeholder: 'Pick a date',
      locale: 'en',
    },
  },
  ar: {
    dir: 'rtl',
    values: {
      label: 'تاريخ الميلاد',
      placeholder: 'اختر تاريخًا',
      locale: 'ar',
    },
  },
  he: {
    dir: 'rtl',
    values: {
      label: 'תאריך לידה',
      placeholder: 'בחרו תאריך',
      locale: 'he',
    },
  },
};

@Component({
  selector: 'z-demo-date-picker-rtl',
  imports: [ZardDatePickerComponent],
  template: `
    <div class="flex flex-col gap-2">
      <span class="text-sm font-medium">{{ i18n.t().label }}</span>
      <z-date-picker [zPlaceholder]="i18n.t().placeholder" [zLocale]="i18n.t().locale" [(value)]="selectedDate" />
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoDatePickerRtlComponent {
  protected readonly i18n = injectRtlTranslation(translations);
  protected readonly selectedDate = signal<CalendarValue>(null);
}

API Reference

z-date-picker

A button that opens a z-calendar in a popover.

Prop
[class]

Custom CSS classes

Type
ClassValue
Default
''
[zId]

Id of the trigger button, for <label for>

Type
string
Default
''
[zType]

Trigger button variant

Type
ZardButtonTypeVariants
Default
'outline'
[zSize]

Trigger height

Type
'xs' | 'sm' | 'default' | 'lg'
Default
'default'
[zIcon]

Trigger icon

Type
'chevron' | 'calendar' | 'none'
Default
'chevron'
[value]

Selected date, or dates in range and multiple modes

Type
CalendarValue
Default
null
[zPlaceholder]

Trigger label when nothing is selected

Type
string
Default
'Pick a date'
[zFormat]

DatePipe format of the label

Type
string
Default
'MMMM d, yyyy'
[zMode]

Selection mode

Type
'single' | 'multiple' | 'range'
Default
'single'
[zCaptionLayout]

Calendar month/year caption style

Type
'label' | 'dropdown' | 'dropdown-months' | 'dropdown-years'
Default
'label'
[zNumberOfMonths]

Months shown side by side

Type
number
Default
1
[zLocale]

BCP 47 locale; falls back to the app locale

Type
string
Default
—
[zDisabledDates]

Days that cannot be selected

Type
Date[]
Default
[]
[zShowOutsideDays]

Shows days of adjacent months

Type
boolean
Default
true
[zAlign]

Popover alignment to the trigger

Type
'start' | 'center' | 'end'
Default
'start'
[minDate]

Minimum selectable date

Type
Date | null
Default
null
[maxDate]

Maximum selectable date

Type
Date | null
Default
null
[disabled]

Disables the date picker

Type
boolean
Default
false
(dateChange)

Emitted when the selection changes or is cleared

Type
EventEmitter<CalendarValue>
Default
—
github iconwhatsapp icondiscord iconX icon

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