# Date picker

A date field with a calendar panel, for single dates, date ranges and optionally a time of day. Users can type the date or pick it from the calendar.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-date-picker`
- Source: [libs/ui/src/lib/molecules/date-picker/date-picker.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/date-picker/date-picker.ts)

```typescript title="Import"
import { DatePicker } from '@vigdx/ui/date-picker';
```

## Basic

Bind `[(value)]` to a `Date | null` signal. Click the field or the calendar button to open the panel, or type a date in the `format` (default `dd.MM.yyyy`). `clearable` adds a button that resets the value to `null`.

```typescript title="date-picker-basic.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DatePicker } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DatePicker],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-date-picker label="Start date" [(value)]="start" />
      <vig-date-picker
        label="Due date"
        placeholder="dd.mm.yyyy"
        [clearable]="true"
        [(value)]="due"
      />
    </div>
    <p class="text-sm text-muted-foreground">
      Start: {{ start()?.toDateString() ?? 'none' }} · Due: {{ due()?.toDateString() ?? 'none' }}
    </p>
  `,
})
export class DatePickerBasicDemo {
  protected readonly start = signal<Date | null>(new Date(2026, 7, 15));
  protected readonly due = signal<Date | null>(null);
}
```

## Range

`selectionMode="range"` makes the value a `DateRange` (`{ start, end }`). The first click sets `start`, the second `end`; `end` stays `null` in between. `rangeSeparator` sets the text between the two dates.

```typescript title="date-picker-range.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { DatePicker, type DateRange } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-range',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DatePicker],
  template: `
    <div class="max-w-sm">
      <vig-date-picker
        label="Reporting period"
        selectionMode="range"
        [clearable]="true"
        [(value)]="period"
      />
    </div>
    <p class="text-sm text-muted-foreground">
      Start: {{ period()?.start?.toDateString() ?? '–' }} · End:
      {{ period()?.end?.toDateString() ?? '–' }}
    </p>
  `,
})
export class DatePickerRangeDemo {
  protected readonly period = signal<DateRange | null>({
    start: new Date(2026, 7, 10),
    end: new Date(2026, 7, 20),
  });
}
```

## Minimum and maximum

`minDate` and `maxDate` disable the days outside the range in the calendar and keep keyboard navigation inside it. `min` and `max` are the same bounds under the names Signal Forms binds: with `[formField]`, `minDate()` and `maxDate()` schema rules reach the calendar on their own, and their errors show the bound in the field format. State the range in the `hint` too.

```typescript title="date-picker-min-max.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DatePicker } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-min-max',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DatePicker],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-date-picker
        label="Delivery date"
        hint="Between 10 and 20 August 2026."
        [value]="delivery"
        [minDate]="min"
        [maxDate]="max"
      />
      <vig-date-picker
        label="Stay"
        selectionMode="range"
        hint="Within August 2026."
        [minDate]="monthStart"
        [maxDate]="monthEnd"
      />
    </div>
  `,
})
export class DatePickerMinMaxDemo {
  protected readonly delivery = new Date(2026, 7, 15);
  protected readonly min = new Date(2026, 7, 10);
  protected readonly max = new Date(2026, 7, 20);
  protected readonly monthStart = new Date(2026, 7, 1);
  protected readonly monthEnd = new Date(2026, 7, 31);
}
```

## Time

`showTime` adds hour and minute fields under the calendar, `showSeconds` a seconds field, and `hourFormat="12"` an AM/PM switch (`meridiemLabels`).

```typescript title="date-picker-time.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DatePicker } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-time',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DatePicker],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-date-picker label="Appointment" [showTime]="true" [value]="appointment" />
      <vig-date-picker
        label="Logged at"
        hourFormat="12"
        format="MM/dd/yyyy"
        [showTime]="true"
        [showSeconds]="true"
        [value]="logged"
      />
    </div>
  `,
})
export class DatePickerTimeDemo {
  protected readonly appointment = new Date(2026, 7, 15, 14, 30);
  protected readonly logged = new Date(2026, 7, 15, 9, 5, 42);
}
```

## Locale and format

Month and day names and all button labels follow the locale set with `provideVigdxUi` or `VigdxI18n.setLocale`. `format` takes the tokens `dd`, `d`, `MM`, `M`, `yyyy` and `yy`, `firstDayOfWeek` is 0 (Sunday) to 6, and every text can also be set per instance.

```typescript title="date-picker-locale.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DatePicker } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-locale',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DatePicker],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <!-- Week starts on Sunday, ISO-style display format. -->
      <vig-date-picker
        label="Start date (US week)"
        format="yyyy-MM-dd"
        [firstDayOfWeek]="0"
        [value]="date"
      />
      <!-- Per-instance Turkish texts. -->
      <vig-date-picker
        label="Başlangıç tarihi"
        placeholder="gg.aa.yyyy"
        dialogAriaLabel="Tarih seçin"
        toggleAriaLabel="Takvimi aç"
        clearAriaLabel="Tarihi temizle"
        prevAriaLabel="Önceki"
        nextAriaLabel="Sonraki"
        [monthNames]="monthNames"
        [monthNamesShort]="monthNamesShort"
        [dayNames]="dayNames"
        [dayNamesMin]="dayNamesMin"
        [clearable]="true"
        [value]="date"
      />
    </div>
  `,
})
export class DatePickerLocaleDemo {
  protected readonly date = new Date(2026, 7, 15);
  protected readonly monthNames = [
    'Ocak',
    'Şubat',
    'Mart',
    'Nisan',
    'Mayıs',
    'Haziran',
    'Temmuz',
    'Ağustos',
    'Eylül',
    'Ekim',
    'Kasım',
    'Aralık',
  ];
  protected readonly monthNamesShort = this.monthNames.map((name) => name.slice(0, 3));
  // Day names start with Sunday, whatever firstDayOfWeek is.
  protected readonly dayNames = [
    'Pazar',
    'Pazartesi',
    'Salı',
    'Çarşamba',
    'Perşembe',
    'Cuma',
    'Cumartesi',
  ];
  protected readonly dayNamesMin = ['Pz', 'Pt', 'Sa', 'Ça', 'Pe', 'Cu', 'Ct'];
}
```

## Label, error, states and sizes

`labelPosition="top"` puts the label above the field and `hideLabel` hides it for toolbars. Errors show once the field is `touched` and `invalid`. `readonly` keeps the field focusable but does not open the calendar.

```typescript title="date-picker-states.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { DatePicker } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-states',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DatePicker],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-date-picker
        label="Valid from"
        labelPosition="top"
        placeholder="dd.mm.yyyy"
        hint="The contract starts on this day."
      />
      <vig-date-picker
        label="Due date"
        labelPosition="top"
        placeholder="dd.mm.yyyy"
        [required]="true"
        [touched]="true"
        [invalid]="true"
        [errors]="[{ kind: 'required' }]"
        [errorMessages]="{ required: 'Please pick a date.' }"
      />
      <vig-date-picker label="Disabled" [value]="date" [disabled]="true" />
      <vig-date-picker label="Read-only" [value]="date" [readonly]="true" />
    </div>
    <div class="grid gap-4 sm:grid-cols-3">
      <vig-date-picker label="Small" size="sm" [value]="date" />
      <vig-date-picker label="Large" size="lg" [value]="date" />
      <vig-date-picker label="Created on" placeholder="Created on" [hideLabel]="true" />
    </div>
  `,
})
export class DatePickerStatesDemo {
  protected readonly date = new Date(2026, 7, 15);
}
```

## Reactive Forms

Import `VigValueAccessor` next to the component to use `formControlName`, `[formControl]` or `ngModel`. Type the control as `Date | null`, or `DateRange | null` in range mode.

```typescript title="date-picker-reactive-forms.ts"
import { JsonPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Button } from '@vigdx/ui/button';
import { VigValueAccessor } from '@vigdx/ui/core';
import { DatePicker, type DateRange } from '@vigdx/ui/date-picker';

@Component({
  selector: 'app-date-picker-reactive-forms',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [JsonPipe, ReactiveFormsModule, Button, DatePicker, VigValueAccessor],
  template: `
    <form class="flex flex-col gap-4" [formGroup]="form" (ngSubmit)="submit()">
      <div class="grid gap-4 sm:grid-cols-2">
        <vig-date-picker label="Birthday" formControlName="birthday" />
        <vig-date-picker label="Vacation" selectionMode="range" formControlName="vacation" />
      </div>
      <div class="flex gap-2">
        <vig-button type="submit" label="Save" />
        <vig-button label="Reset" variant="secondary" (click)="form.reset()" />
      </div>
      <pre class="rounded-input bg-subtle p-3 font-mono text-xs">{{ form.value | json }}</pre>
    </form>
  `,
})
export class DatePickerReactiveFormsDemo {
  protected readonly form = new FormGroup({
    birthday: new FormControl<Date | null>(null, Validators.required),
    vacation: new FormControl<DateRange | null>(null),
  });

  protected submit(): void {
    this.form.markAllAsTouched();
  }
}
```

## Signal Forms

`vig-date-picker` implements `FormValueControl` for `Date | null` (or `DateRange | null`). A `validate()` rule can compare two dates of the model.

```typescript title="date-picker-signal-forms.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { FormField, form, required, validate } from '@angular/forms/signals';
import { DatePicker } from '@vigdx/ui/date-picker';

interface Booking {
  checkIn: Date | null;
  checkOut: Date | null;
}

@Component({
  selector: 'app-date-picker-signal-forms',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [FormField, DatePicker],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-date-picker label="Check-in" [formField]="booking.checkIn" />
      <vig-date-picker label="Check-out" [formField]="booking.checkOut" />
    </div>
    <p class="text-sm text-muted-foreground">Valid: {{ booking().valid() ? 'yes' : 'no' }}</p>
  `,
})
export class DatePickerSignalFormsDemo {
  // Date fields are empty as null.
  protected readonly model = signal<Booking>({ checkIn: new Date(2026, 7, 15), checkOut: null });
  protected readonly booking = form(this.model, (path) => {
    required(path.checkIn);
    required(path.checkOut);
    validate(path.checkOut, ({ value, valueOf }) => {
      const checkIn = valueOf(path.checkIn);
      const checkOut = value();
      return checkIn && checkOut && checkOut <= checkIn
        ? { kind: 'order', message: 'Check-out must be after check-in.' }
        : undefined;
    });
  });
}
```

## Storing dates

The value is a `Date` at local midnight of the chosen day. A `Date` is an instant, not a calendar day, so do not persist it with `toISOString()` or `JSON.stringify`: 15 March at midnight in Istanbul becomes `2026-03-14T21:00:00.000Z`, and anyone reading it in another time zone can land on a different day. For birthdays, due dates and other calendar dates, store the ISO calendar date instead:

```
import { parseIsoDate, toIsoDate } from '@vigdx/ui';

save() {
  this.api.update({ dueDate: toIsoDate(this.dueDate()) }); // '2026-03-15'
}
load(saved: Task) {
  this.dueDate.set(parseIsoDate(saved.dueDate)); // local 15 March, any time zone
}
```

`toIsoDate` reads the local calendar day (`null` stays `null`); `parseIsoDate` returns local midnight of that day, or `null` for anything that is not a valid `YYYY-MM-DD` date. Avoid `new Date('2026-03-15')`: it parses as UTC midnight and shows the previous day west of Greenwich. With `showTime` the value is a real moment, so persist it as an instant (for example `toISOString()`) together with the time zone it was meant in.

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="date-picker"][data-part="field"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="date-picker"]`

| Part | Element | data-state |
| --- | --- | --- |
| `field` | Positioned wrapper of the label and the control. |   |
| `label` | The visible (or floating) label. |   |
| `input` | The native `<input>`. |   |
| `hint` | The `vig-hint` (a `display: contents` host; style its `text` part). |   |
| `disabled-reason` | The `vig-hint` with the disabled reason (`display: contents`). |   |
| `error` | The `vig-field-error` (a `display: contents` host; style its `message` part). |   |
| `clear` | The clear button (`clearable`). |   |
| `trigger` | The calendar button. |   |
| `panel` | The calendar dialog, rendered in the overlay container. |   |
| `header` | Navigation row: previous, view switch, next. |   |
| `prev` | Previous month, year or decade. |   |
| `view-switch` | Month and year button that cycles the views. |   |
| `next` | Next month, year or decade. |   |
| `grid` | The `role="grid"` day grid. |   |
| `weekday` | A weekday column header. |   |
| `day` | A day cell (`aria-selected`, `aria-current="date"`) with its date as `data-date="YYYY-MM-DD"`; `outside` marks days of the neighbouring months. | `outside` |
| `months` | The month view grid. |   |
| `month` | A month cell (`aria-pressed`). |   |
| `years` | The year view grid. |   |
| `year` | A year cell (`aria-pressed`). |   |
| `time` | The time row (`showTime`). |   |
| `time-input` | An hour, minute or second field. |   |
| `meridiem` | The AM/PM toggle (`hourFormat="12"`). |   |

| Attribute | Meaning |
| --- | --- |
| `data-date` | On each day cell (`[data-part="day"]`): its date, `YYYY-MM-DD`. |

## Accessibility

- The text input has `role="combobox"` with `aria-haspopup="dialog"` and `aria-expanded`; the calendar opens in a labelled `role="dialog"` (`dialogAriaLabel`).
- The days form a `role="grid"`: the arrows move by day and week (mirrored under right-to-left), Home and End go to the start and end of the week, Page Up and Page Down change the month (with Shift, the year), Enter or Space select, Escape closes.
- The calendar renders at the end of the page, so leaving it with Tab past its last control continues from the field and Shift+Tab before its first control returns to the field; either way the calendar closes. When it closes while focus is inside (scrolling, a click on a blank area), focus goes back to the field instead of being lost.
- Selected days set `aria-selected` and today `aria-current="date"`; days outside `minDate` / `maxDate` are disabled. Selected days, months and years keep the system selection colors in forced-colors mode, and the days inside a range are marked by a border, not by a tint alone.
- The calendar, clear, previous and next buttons and the time fields have their own labels, all translatable through inputs or the locale.
- Typing stays possible, so tell users the expected `format`, for example with a `placeholder` or `hint`.
- The month header (also the grid's name) is worded and ordered by `Intl.DateTimeFormat` for the active locale, e.g. “2026年3月”. A language registered without calendar names gets its month and weekday names from Intl as well.

## API

### DatePicker

Selector: `vig-date-picker` · Kind: component

Date field with a calendar panel. Each day cell of the calendar carries its date as `data-date="YYYY-MM-DD"`; days of the neighbouring months shown in the grid also carry `data-state="outside"`. data-date

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `clearable` | `boolean` | `false` | — |
| `clearAriaLabel` | `string \| undefined` | `undefined` | — |
| `dayNames` | `readonly string[] \| undefined` | `undefined` | — |
| `dayNamesMin` | `readonly string[] \| undefined` | `undefined` | — |
| `dialogAriaLabel` | `string \| undefined` | `undefined` | — |
| `dirty` | `boolean` | `false` | — |
| `disabled` | `boolean` | `false` | — |
| `disabledReasons` | `readonly WithOptionalFieldTree<DisabledReason>[]` | `[]` | — |
| `errorMessages` | `Record<string, string>` | — | — |
| `errors` | `readonly ValidationError.WithOptionalFieldTree[]` | `[]` | — |
| `firstDayOfWeek` | `number` | `1` | 0 = Sunday … 6 = Saturday. Defaults to Monday (ISO 8601). |
| `format` | `string` | `'dd.MM.yyyy'` | DatePipe-style tokens: dd, d, MM, M, yyyy, yy. PrimeNG's dd.mm.yy ⇒ dd.MM.yyyy. |
| `hidden` | `boolean` | `false` | — |
| `hideLabel` | `boolean` | `false` | Visually hides the label — it still names the control for assistive tech — and drops the row reserved for it, giving a shorter control for dense toolbars such as table filters. Pair it with a placeholder. |
| `hint` | `string \| undefined` | `undefined` | — |
| `hourAriaLabel` | `string \| undefined` | `undefined` | — |
| `hourFormat` | `"12" \| "24"` | `'24'` | — |
| `invalid` | `boolean` | `false` | — |
| `label` (required) | `string` | — | — |
| `labelPosition` | `LabelPosition` | `'float'` | `float` (default) rests the label inside the field; `top` sets it above a shorter field, for forms laid out with labels over their controls. |
| `max` | `Date \| undefined` | `undefined` | Latest selectable day: a `Date` or an ISO `yyyy-MM-dd` string, bound from a `maxDate()` schema rule by `[formField]`. An alias of `maxDate`; when both are set, the earlier day wins. |
| `maxDate` | `Date \| undefined` | `undefined` | Latest selectable day; the same bound as `max`. |
| `meridiemLabels` | `readonly [string, string] \| undefined` | `undefined` | — |
| `min` | `Date \| undefined` | `undefined` | Earliest selectable day: a `Date` or an ISO `yyyy-MM-dd` string. Signal Forms binds it from a `minDate()` schema rule through `[formField]`, so the calendar disables the days the validator rejects. An alias of `minDate`; when both are set, the later day wins. |
| `minDate` | `Date \| undefined` | `undefined` | Earliest selectable day; the same bound as `min`. |
| `minuteAriaLabel` | `string \| undefined` | `undefined` | — |
| `monthNames` | `readonly string[] \| undefined` | `undefined` | Month names, January first; the locale's labels by default. The calendar header ("March 2026") is otherwise worded and ordered by `Intl.DateTimeFormat`; given names replace its month. |
| `monthNamesShort` | `readonly string[] \| undefined` | `undefined` | — |
| `name` | `string` | `''` | — |
| `nextAriaLabel` | `string \| undefined` | `undefined` | — |
| `pending` | `boolean` | `false` | — |
| `placeholder` | `string \| undefined` | `undefined` | — |
| `prevAriaLabel` | `string \| undefined` | `undefined` | — |
| `rangeSeparator` | `string` | `' – '` | — |
| `readonly` | `boolean` | `false` | — |
| `required` | `boolean` | `false` | — |
| `secondAriaLabel` | `string \| undefined` | `undefined` | — |
| `selectionMode` | `DatePickerSelectionMode` | `'single'` | — |
| `showSeconds` | `boolean` | `false` | — |
| `showTime` | `boolean` | `false` | — |
| `size` | `FieldSize` | `'md'` | — |
| `toggleAriaLabel` | `string \| undefined` | `undefined` | — |
| `touched` | `boolean` | `false` | — |
| `value` (model) | `T \| null` | `null` | — |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `touch` | `void` | — |
| `valueChange` | `T \| null` | — |

#### Methods

| Signature | Description |
| --- | --- |
| `focus(options?: FocusOptions): void` | Moves focus to the control's interactive element (the input, or the trigger of a popup control). Signal Forms calls it through `field().focusBoundControl()`; the host element itself cannot take focus. |
| `reset(): void` | Drops typed text and closes the calendar; see `VigFormField.reset`. |

### VigValueAccessor

Kind: directive

Bridges the vigdx form fields to Reactive Forms (`formControl`, `formControlName`) and template-driven forms (`ngModel`). Import it next to the component; Signal Forms (`[formField]`) need no accessor.

#### Methods

| Signature | Description |
| --- | --- |
| `registerOnChange(fn: (value: unknown) => void): void` | — |
| `registerOnTouched(fn: () => void): void` | — |
| `setDisabledState(disabled: boolean): void` | — |
| `writeValue(value: unknown): void` | — |
