Primitives
A date picker is a component that allows users to select a date from a calendar and navigate through months and years.
Import the DatePicker primitives from ng-primitives/date-picker
.
import {
NgpDatePicker,
NgpDatePickerLabel,
NgpDatePickerNextMonth,
NgpDatePickerPreviousMonth,
NgpDatePickerGrid,
NgpDatePickerCell,
NgpDatePickerRowRender,
NgpDatePickerCellRender,
NgpDatePickerDateButton,
} from 'ng-primitives/date-picker';
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>
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:
The outermost container for the date picker.
[ngpDatePicker]
ngpDatePicker
The following data attributes are available on the ngpDatePicker
directive:
Attribute | Description | Value |
---|---|---|
data-disabled |
The disabled state of the date picker. | true | false |
The label that displays the current month and year typically in the header of the date picker. This will be announced by screen readers when the date changes.
[ngpDatePickerLabel]
ngpDatePickerLabel
The following data attributes are available on the ngpDatePickerLabel
directive:
Attribute | Description | Value |
---|---|---|
data-disabled |
The disabled state of the date picker. | true | false |
A button that navigates to the previous month.
[ngpDatePickerPreviousMonth]
ngpDatePickerPreviousMonth
The following data attributes are available on the ngpDatePickerPreviousMonth
directive:
Attribute | Description | Value |
---|---|---|
data-hover |
The hover state of the button. | true | false |
data-focus-visible |
The focus state of the button. | true | false |
data-press |
The pressed state of the button. | true | false |
data-disabled |
The disabled state of the button. | true | false |
A button that navigates to the next month.
[ngpDatePickerNextMonth]
ngpDatePickerNextMonth
The following data attributes are available on the ngpDatePickerNextMonth
directive:
Attribute | Description | Value |
---|---|---|
data-hover |
The hover state of the button. | true | false |
data-focus-visible |
The focus state of the button. | true | false |
data-press |
The pressed state of the button. | true | false |
data-disabled |
The disabled state of the button. | true | false |
The grid that contains the days of the month.
[ngpDatePickerGrid]
ngpDatePickerGrid
The following data attributes are available on the ngpDatePickerGrid
directive:
Attribute | Description | Value |
---|---|---|
data-disabled |
The disabled state of the date picker. | true | false |
A structural directive that renders a row of weekdays in the date picker grid.
*ngpDatePickerRowRender
ngpDatePickerRowRender
A structural directive that renders a cell in the date picker grid.
*ngpDatePickerCellRender
ngpDatePickerCellRender
The following context fields are available on the ngpDatePickerCellRender
directive:
A cell in the date picker grid.
[ngpDatePickerCell]
ngpDatePickerCell
The following data attributes are available on the ngpDatePickerCell
directive:
Attribute | Description | Value |
---|---|---|
data-disabled |
The disabled state of the date picker. | true | false |
data-selected |
The selected state of the date. | true | false |
A button that represents a date in the date picker grid.
[ngpDatePickerDateButton]
ngpDatePickerDateButton
The following data attributes are available on the ngpDatePickerDateButton
directive:
Attribute | Description | Value |
---|---|---|
data-selected |
The selected state of the button. | true | false |
data-outside-month |
The state of the button if it is outside the current month. | true | false |
data-today |
The state of the button if it is today. | true | false |
data-hover |
The hover state of the button. | true | false |
data-focus-visible |
The focus state of the button. | true | false |
data-press |
The pressed state of the button. | true | false |
data-disabled |
The disabled state of the button. | true | false |
Adheres to the WAI-ARIA design pattern.
Copyright © 2024 Angular Primitives