Primitives

Date Picker

A date picker is a component that allows users to select a date from a calendar and navigate through months and years.

Import

Import the DatePicker primitives from ng-primitives/date-picker.

import {
  NgpDatePicker,
  NgpDateRangePicker,
  NgpDatePickerLabel,
  NgpDatePickerNextMonth,
  NgpDatePickerPreviousMonth,
  NgpDatePickerGrid,
  NgpDatePickerCell,
  NgpDatePickerRowRender,
  NgpDatePickerCellRender,
  NgpDatePickerDateButton,
} from 'ng-primitives/date-picker';

Usage

Assemble the date-picker directives in your template.

<div ngpDatePicker>
  <div>
    <button ngpDatePickerPreviousMonth>...</button>
    <h2 ngpDatePickerLabel>...</h2>
    <button ngpDatePickerNextMonth>...</button>
  </div>
  <table ngpDatePickerGrid>
    <thead>
      <tr>
        <th scope="col" abbr="Sunday">S</th>
        ...
      </tr>
    </thead>
    <tbody>
      <tr *ngpDatePickerRowRender>
        <td *ngpDatePickerCellRender="let date" ngpDatePickerCell>
          <button ngpDatePickerDateButton>...</button>
        </td>
      </tr>
    </tbody>
  </table>
</div>

Reusable Component

Create a reusable component that uses the date picker directives.

Schematics

Generate a reusable date-picker component using the Angular CLI.

ng g ng-primitives:primitive date-picker

Options

  • path: The path at which to create the component file.
  • prefix: The prefix to apply to the generated component selector.
  • componentSuffix: The suffix to apply to the generated component class name.
  • fileSuffix: The suffix to apply to the generated component file name. Defaults to component.
  • exampleStyles: Whether to include example styles in the generated component file. Defaults to true.

Examples

Here are some additional examples of how to use the Date Picker primitives.

Date Range Picker

The date range picker allows users to select a range of dates by selecting the start and end dates.

API Reference

By default, the date picker uses the native JavaScript Date object, however the date picker is designed to work with any date library. To use a date library, such as Luxon, you need to specify the appropriate date adapter. The date adapter is an abstraction layer that allows components to use date objects from any date library, ensuring compatibility and easy integration. To learn more about the date adapter, see the Date Adapter documentation.

The following directives are available to import from the ng-primitives/date-picker package:

NgpDatePicker

Data Attributes

The following data attributes are available on the ngpDatePicker directive:

Attribute Description
data-disabled Applied when the date picker is disabled.

NgpDateRangePicker

Data Attributes

The following data attributes are available on the ngpDateRangePicker directive:

Attribute Description
data-disabled Applied when the date range picker is disabled.

NgpDatePickerLabel

Data Attributes

The following data attributes are available on the ngpDatePickerLabel directive:

Attribute Description
data-disabled Applied when the date picker is disabled.

NgpDatePickerPreviousMonth

Data Attributes

The following data attributes are available on the ngpDatePickerPreviousMonth directive:

Attribute Description
data-hover Applied when the button is hovered.
data-focus-visible Applied when the button is focused.
data-press Applied when the button is pressed.
data-disabled Applied when the button is disabled.

NgpDatePickerNextMonth

Data Attributes

The following data attributes are available on the ngpDatePickerNextMonth directive:

Attribute Description
data-hover Applied when the button is hovered.
data-focus-visible Applied when the button is focused.
data-press Applied when the button is pressed.
data-disabled Applied when the button is disabled.

NgpDatePickerGrid

Data Attributes

The following data attributes are available on the ngpDatePickerGrid directive:

Attribute Description
data-disabled Applied when the date picker is disabled.

NgpDatePickerRowRender

NgpDatePickerCellRender

A structural directive that renders a cell in the date picker grid.

  • Selector: *ngpDatePickerCellRender
  • Exported As: ngpDatePickerCellRender

The following context fields are available on the ngpDatePickerCellRender directive:

The date value for the cell.

NgpDatePickerCell

Data Attributes

The following data attributes are available on the ngpDatePickerCell directive:

Attribute Description
data-disabled Applied when the cell is disabled.
data-selected Applied when the cell is selected.

NgpDatePickerDateButton

Data Attributes

The following data attributes are available on the ngpDatePickerDateButton directive:

Attribute Description
data-selected Applied when the button is selected.
data-outside-month Applied when the button is outside the current month.
data-today Applied when the button represents the current date.
data-hover Applied when the button is hovered.
data-focus-visible Applied when the button is focused.
data-press Applied when the button is pressed.
data-disabled Applied when the button is disabled.
data-range-start Applied when the button is the start of a date range.
data-range-end Applied when the button is the end of a date range.
data-range-between Applied when the button is between the start and end of a date range.

Accessibility

Adheres to the WAI-ARIA design pattern.

Keyboard Interactions

  • Space - Selects the focused date.
  • Enter - Selects the focused date.
  • ArrowUp - Moves focus to the same day of the previous week.
  • ArrowDown - Moves focus to the same day of the next week.
  • ArrowLeft - Moves focus to the previous day.
  • ArrowRight - Moves focus to the next day.
  • Home - Moves focus to the first day of the month.
  • End - Moves focus to the last day of the month.
  • PageUp - Moves focus to the same date in the previous month.
  • PageDown - Moves focus to the same date in the next month.

Global Configuration

You can configure the default options for all NgpDatePicker and NgpDateRangePicker calendars in your application by using the provideDatePickerConfig function in a providers array.

import { provideDatePickerConfig } from 'ng-primitives/date-picker';

bootstrapApplication(AppComponent, {
  providers: [
    provideDatePickerConfig({
      firstDayOfWeek: 1, // Monday
    }),
  ],
});

NgpDatePickerConfig

Sets which day starts the week in date picker and date range picker calendars. Accepts 1-7 where:
  • 1=Monday,
  • 2=Tuesday,
  • 3=Wednesday,
  • 4=Thursday,
  • 5=Friday,
  • 6=Saturday,
  • 7=Sunday (default).
Choose based on your users' cultural expectations - most international applications use 1 (Monday), while US applications typically use 7 (Sunday).
Note: When using a non-Sunday start day, update your calendar header column order accordingly.

Copyright © 2026 Angular Primitives

This site is powered by Netlify