DatePicker
Import |
Docs |
When To Use#
By clicking the input box, you can select a date from a popup calendar.
Examples #
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
Loading...
Loading...
Loading...
API#
Note: Some of date-picker's locale are coming from Angular i18n, that should be provided in the file app.config.ts.
For example:
import { registerLocaleData } from '@angular/common';
import en from '@angular/common/locales/en';
registerLocaleData(en);
Note: All input and output date objects are Date, you can manipulate it with date-fns.
Common API#
The following APIs are shared by nz-date-picker, nz-range-picker.
| Property | Description | Type | Default | Global Config | Version |
|---|---|---|---|---|---|
[nzId] | input id attribute inside the component | string | - | ||
[nzAllowClear] | Whether to show clear button | boolean | true | - | |
[nzAutoFocus] | get focus when component mounted | boolean | false | - | |
[nzBackdrop] | whether or not the overlay should attach a backdrop | boolean | false | ||
[nzDefaultPickerValue] | default picker date | Date | Date[] | - | - | |
[nzDisabled] | determine whether the nz-date-picker is disabled | boolean | false | - | |
[nzDisabledDate] | specify the date that cannot be selected | (current: Date) => boolean | - | - | |
[nzDropdownClassName] | to customize the className of the popup calendar | string | - | - | |
[nzFormat] | to set the date format, see nzFormat special instructions | string | - | ||
[nzInputReadOnly] | set the readonly attribute of the input tag (avoids virtual keyboard on touch devices) | boolean | false | - | |
[nzLocale] | localization configuration | object | default | - | |
[nzMode] | Set picker mode | 'date' | 'week' | 'month' | 'quarter' | 'year' | 'date' | ||
[nzPlaceHolder] | placeholder of date input | string | string[] | - | ||
[nzPopupStyle] | to customize the style of the popup calendar | object | {} | - | |
[nzPrefix] | to customize the prefix | string | TemplateRef | 22.2.0 | ||
| - | |||||
[nzRenderExtraFooter] | render extra footer in panel | TemplateRef | string | (() => TemplateRef | string) | - | ||
[nzSize] | determine the size of the input box, the height of large and small, are 40px and 24px respectively, while default size is 32px | 'large' | 'small' | - | - | |
[nzStatus] | Set validation status | 'error' | 'warning' | - | ||
[nzPlacement] | The position where the selection box pops up | 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight' | 'bottomLeft' | ||
[nzSuffixIcon] | the custom suffix icon | string | TemplateRef | - | ✅ | |
[nzVariant] | Variants of DatePicker | 'outlined' | 'borderless' | 'filled' | 'underlined' | 'outlined' | ✅ | 20.0.0 |
[nzInline] | inline mode | boolean | false | - | |
(nzOnOpenChange) | a callback emitter, can be executed whether the popup calendar is popped up or closed | EventEmitter<boolean> | - | - | |
(nzOnPanelChange) | a callback emitter, can be executed when the panel changes | EventEmitter<NzPanelChangeType> | - | - |
Custom clear icon (22.2.0)#
Mark a child element with the static nzDatePickerClearIcon attribute to replace the clear icon, following the same content projection pattern as Input’s nzInputClearIcon. This works with both nz-date-picker and nz-range-picker, including all picker modes. No additional directive import is needed.
If no custom content is provided, the filled close-circle icon is used. nzAllowClear still controls whether clearing is allowed; the clear icon is hidden when the picker is disabled or empty. The picker handles the click and clears the value, so the custom content does not need its own click handler. Use a non-interactive element such as nz-icon, span or svg.
<nz-date-picker [(ngModel)]="date">
<nz-icon nzDatePickerClearIcon nzType="close" />
</nz-date-picker>
<nz-range-picker [(ngModel)]="range">
<nz-icon nzDatePickerClearIcon nzType="close" />
</nz-range-picker>
Common Methods#
| Name | Description |
|---|---|
open() | open calendar panel |
close() | close calendar panel |
nz-date-picker#
| Property | Description | Type | Default |
|---|---|---|---|
[(ngModel)] | Date | Date | - |
nz-date-picker[nzMode="date"]#
| Property | Description | Type | Default |
|---|---|---|---|
[nzDateRender] | custom rendering function for date cells (Not support by month-picker/year-picker) | - | TemplateRef<Date> | string | ((d: Date) => TemplateRef<Date> | string) |
[nzDisabledTime] | to specify the time that cannot be selected | (current: Date) => { nzDisabledHours, nzDisabledMinutes, nzDisabledSeconds } | - |
[nzShowTime] | to provide an additional time selection | object | boolean | TimePicker Options |
[nzShowToday] | whether to show 'Today' button | boolean | true |
[nzShowNow] | whether to show 'Now' button on panel when nzShowTime is set | boolean | true |
[nzShowWeekNumber] | whether to show the week number on each row (Only supported by date picker. Week picker always shows week numbers) | boolean | false |
(nzOnOk) | callback when click ok button | EventEmitter<Date> | - |
nz-range-picker#
| Property | Description | Type | Default |
|---|---|---|---|
[(ngModel)] | Date | Date[] | - |
[nzRanges] | preseted ranges for quick selection | { [ key: string ]: Date[] } | { [ key: string ]: () => Date[] } | - |
[nzSeparator] | separator | string | TemplateRef | '~' |
(nzOnCalendarChange) | The start time or the end time of the range change callback | EventEmitter<Date[]> | - |
nz-range-picker[nzMode="date"]#
| Property | Description | Type | Default |
|---|---|---|---|
[nzShowTime] | to provide an additional time selection | object | boolean | TimePicker Options |
[nzDisabledTime] | to specify the time that cannot be selected | (current: Date, partial: 'start' | 'end') => { nzDisabledHours, nzDisabledMinutes, nzDisabledSeconds } | - |
[nzShowWeekNumber] | whether to show the week number on each row (Only supported by date picker. Week picker always shows week numbers) | boolean | false |
(nzOnOk) | click ok callback | EventEmitter<Date[]> | - |
Currently, supported
nz-time-pickerparameters innzShowTimeare:nzFormat,nzHourStep,nzMinuteStep,nzSecondStep,nzDisabledHours,nzDisabledMinutes,nzDisabledSeconds,nzHideDisabledOptions,nzDefaultOpenValue,nzAddOn
FAQ#
How to use custom date library in Date-Picker#
Refer to Date Adapter.
The overlay layer element does not follow the scroll position when scrolling#
By default, the overlay layer element uses body as the scroll container. If using another scroll container, add the CdkScrollable directive to the custom scroll container element.
Note: You need to import the CdkScrollable directive or ScrollingModule module from @angular/cdk/scrolling.