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 |
---|---|
data-disabled |
Applied when the date picker is disabled. |
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 |
---|---|
data-disabled |
Applied when the date picker is disabled. |
A button that navigates to the previous month.
[ngpDatePickerPreviousMonth]
ngpDatePickerPreviousMonth
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. |
A button that navigates to the next month.
[ngpDatePickerNextMonth]
ngpDatePickerNextMonth
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. |
The grid that contains the days of the month.
[ngpDatePickerGrid]
ngpDatePickerGrid
The following data attributes are available on the ngpDatePickerGrid
directive:
Attribute | Description |
---|---|
data-disabled |
Applied when the date picker is disabled. |
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 |
---|---|
data-disabled |
Applied when the cell is disabled. |
data-selected |
Applied when the cell is selected. |
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 |
---|---|
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. |
Adheres to the WAI-ARIA design pattern.
Copyright © 2024 Angular Primitives