# Calendar Picker Dialog Box (CalendarPickerDialog) A calendar picker dialog box is a dialog box that allows users to select a date from a calendar picker. > **NOTE** > > This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version. > > The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where [the UI context is unclear](../../../ui/arkts-global-interface.md). For details, see [UIContext](../arkts-apis-uicontext-uicontext.md). ## CalendarPickerDialog ### show static show(options?: CalendarDialogOptions): void Shows a calendar picker dialog box. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Device behavior differences**: On wearables, calling this API results in a runtime exception indicating that the API is undefined. On other devices, the API works correctly. **Parameters** | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------------- | ---- | -------------------------- | | options | [CalendarDialogOptions](#calendardialogoptions) | No | Parameters of the calendar picker dialog box.| ## CalendarDialogOptions Defines the configuration options of the calendar picker dialog box. Inherits from [CalendarOptions](ts-basic-components-calendarpicker.md#calendaroptions). **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Read-Only| Optional| Description | | ---------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | ------------------------------------------------------------ | | onAccept | [Callback](ts-types.md#callback12)\ | No | Yes | Triggered when the OK button in the dialog box is clicked.
The callback parameter represents the selected date value.
**Atomic service API**: This API can be used in atomic services since API version 11.| | onCancel | [VoidCallback](ts-types.md#voidcallback12) | No | Yes | Triggered when the Cancel button in the dialog box is clicked.
**Atomic service API**: This API can be used in atomic services since API version 11. | | onChange | [Callback](ts-types.md#callback12)\ | No | Yes | Triggered when the selection in the picker changes the selected date.
The callback parameter represents the selected date value.
**Atomic service API**: This API can be used in atomic services since API version 11.| | backgroundColor11+ | [ResourceColor](ts-types.md#resourcecolor) | No| Yes| Backplane color of the dialog box.
Default value: **Color.Transparent**
**NOTE**
When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundBlurStyle11+ | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No| Yes| Background blur style of the dialog box.
Default value: **BlurStyle.COMPONENT_ULTRA_THICK**
**NOTE**
Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundBlurStyleOptions19+ | [BackgroundBlurStyleOptions](ts-universal-attributes-background.md#backgroundblurstyleoptions10) | No| Yes| Options for customizing the background blur style.
**Atomic service API**: This API can be used in atomic services since API version 19.| | backgroundEffect19+ | [BackgroundEffectOptions](ts-universal-attributes-background.md#backgroundeffectoptions11) | No| Yes| Options for customizing the background effect.
**Atomic service API**: This API can be used in atomic services since API version 19.| | acceptButtonStyle12+ | [PickerDialogButtonStyle](ts-picker-common.md#pickerdialogbuttonstyle12) | No| Yes| Style of the accept button.
**NOTE**
In the **acceptButtonStyle** and **cancelButtonStyle** configurations, only one **primary** field can be set to **true** at most. If both the **primary** fields are set to **true**, neither will take effect.
**Atomic service API**: This API can be used in atomic services since API version 12.| | cancelButtonStyle12+ | [PickerDialogButtonStyle](ts-picker-common.md#pickerdialogbuttonstyle12) | No| Yes| Style of the cancel button.
**NOTE**
In the **acceptButtonStyle** and **cancelButtonStyle** configurations, only one **primary** field can be set to **true** at most. If both the **primary** fields are set to **true**, neither will take effect.
**Atomic service API**: This API can be used in atomic services since API version 12.| | onDidAppear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box appears.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.
2. You can set the callback event for changing the dialog box display effect in **onDidAppear**. The settings take effect next time the dialog box appears.
3. If the user dismisses the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.
4. If the dialog box is dismissed before its entrance animation is finished, this callback is not invoked.
**Atomic service API**: This API can be used in atomic services since API version 12.| | onDidDisappear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box disappears.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.
**Atomic service API**: This API can be used in atomic services since API version 12.| | onWillAppear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box is about to appear.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.
2. You can set the callback event for changing the dialog box display effect in **onWillAppear**. The settings take effect next time the dialog box appears.
**Atomic service API**: This API can be used in atomic services since API version 12.| | onWillDisappear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box is about to disappear.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.
2. If the user closes the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.
**Atomic service API**: This API can be used in atomic services since API version 12.| | shadow12+ | [ShadowOptions](ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](ts-universal-attributes-image-effect.md#shadowstyle10) | No | Yes | Shadow of the dialog box.
Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise
**Atomic service API**: This API can be used in atomic services since API version 12.| | enableHoverMode14+ | boolean | No | Yes | Whether to respond when the device is in semi-folded mode.
Default value: **false**. The value **true** means to respond when the device is in semi-folded mode, and **false** means the opposite.
**Atomic service API**: This API can be used in atomic services since API version 14.| | hoverModeArea14+ | [HoverModeAreaType](ts-appendix-enums.md#hovermodeareatype14) | No | Yes | Display area of the dialog box when the device is in semi-folded mode.
Default value: **HoverModeAreaType.BOTTOM_SCREEN**
**Atomic service API**: This API can be used in atomic services since API version 14.| | markToday19+ | boolean | No | Yes | Whether to highlight the current system date.
Default value: **false**. The value **true** means to highlight the current system date, and **false** means the opposite.
**Atomic service API**: This API can be used in atomic services since API version 19.| > **NOTE** > > When the application window is resized, the width of the dialog box is continuously compressed. If the window width is reduced below a certain threshold, the content of the dialog box may not be fully visible. To ensure that the content of the **CalendarPickerDialog** component is fully displayed, the minimum window width required is 386 vp. ## Example ### Example 1: Setting the Background This example demonstrates how to set the calendar picker dialog box's background using **backgroundColor**, **backgroundBlurStyle**, and **shadow** in [CalendarDialogOptions](#calendardialogoptions). ```ts // xxx.ets @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date('2024-04-23'); build() { Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { console.info("CalendarDialog.show"); CalendarPickerDialog.show({ selected: this.selectedDate, backgroundColor: Color.Gray, backgroundBlurStyle: BlurStyle.NONE, shadow: ShadowStyle.OUTER_FLOATING_SM, onAccept: (value) => { this.selectedDate = value; console.info("calendar onAccept:" + JSON.stringify(value)); }, onCancel: () => { console.info("calendar onCancel"); }, onChange: (value) => { console.info("calendar onChange:" + JSON.stringify(value)); }, onDidAppear: () => { console.info("calendar onDidAppear"); }, onDidDisappear: () => { console.info("calendar onDidDisappear"); }, onWillAppear: () => { console.info("calendar onWillAppear"); }, onWillDisappear: () => { console.info("calendar onWillDisappear"); } }); }) }.width('100%') } } ``` ![CalendarPickerDialog](figures/CalendarPickerDialog.gif) ### Example 2: Customizing the Button Style This example shows how to customize the calendar picker dialog box's buttons by configuring **acceptButtonStyle** and **cancelButtonStyle** in [CalendarDialogOptions](#calendardialogoptions). ```ts // xxx.ets @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date(); build() { Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { console.info("CalendarDialog.show"); CalendarPickerDialog.show({ selected: this.selectedDate, acceptButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: 'rgb(81, 81, 216)', fontSize: '26fp', fontWeight: FontWeight.Bolder, fontStyle: FontStyle.Normal, fontFamily: 'sans-serif', backgroundColor: '#A6ACAF', borderRadius: 20 }, cancelButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Blue, fontSize: '16fp', fontWeight: FontWeight.Normal, fontStyle: FontStyle.Italic, fontFamily: 'sans-serif', backgroundColor: '#50182431', borderRadius: 10 }, onAccept: (value) => { this.selectedDate = value; console.info("calendar onAccept:" + JSON.stringify(value)); } }); }) }.width('100%') } } ``` ![CalendarPickerDialog](figures/CalendarPickerDialog_CustomButton.png) ### Example 3: Configuring a Dialog Box in the Hover State This example demonstrates how to set the layout area of a dialog box when the device is in semi-folded mode. ```ts @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date('2024-04-23'); build() { Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { console.info("CalendarDialog.show"); CalendarPickerDialog.show({ selected: this.selectedDate, onAccept: (value) => { console.info("calendar onAccept:" + JSON.stringify(value)); }, onCancel: () => { console.info("calendar onCancel"); }, onChange: (value) => { console.info("calendar onChange:" + JSON.stringify(value)); }, onDidAppear: () => { console.info("calendar onDidAppear"); }, onDidDisappear: () => { console.info("calendar onDidDisappear"); }, onWillAppear: () => { console.info("calendar onWillAppear"); }, onWillDisappear: () => { console.info("calendar onWillDisappear"); }, enableHoverMode: true, hoverModeArea: HoverModeAreaType.TOP_SCREEN, }); }) }.width('100%') } } ``` ### Example 4: Setting the Background Style for the Selected Date This example demonstrates how to customize the background style of the selected date using **hintRadius** in [CalendarOptions](ts-basic-components-calendarpicker.md#calendaroptions). ```ts // xxx.ets @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date('2024-04-23'); build() { Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { console.info("CalendarDialog.show"); CalendarPickerDialog.show({ selected: this.selectedDate, hintRadius: 1, onAccept: (value) => { this.selectedDate = value; console.info("calendar onAccept:" + JSON.stringify(value)); } }); }) }.width('100%') } } ``` ### Example 5: Setting Start and End Dates This example demonstrates how to set the start and end dates for the calendar picker dialog box using **start** and **end** in [CalendarOptions](ts-basic-components-calendarpicker.md#calendaroptions). ```ts // xxx.ets @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date('2025-01-01'); private startDate: Date = new Date('2024-01-10'); private endDate: Date = new Date('2025-1-10'); build() { Column() { Text('Calendar date picker').fontSize(30) Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { console.info("CalendarDialog.show"); CalendarPickerDialog.show({ start: this.startDate, end: this.endDate, selected: this.selectedDate, }); }) }.width('100%').margin({ top: 350 }) } } ``` ### Example 6: Highlighting the Current System Date and Disabling a Specific Date Range This example shows how to highlight the current system date using **markToday** in [CalendarDialogOptions](#calendardialogoptions) and disable a specific date range using **disabledDateRange** in [CalendarOptions](ts-basic-components-calendarpicker.md#calendaroptions). ```ts // xxx.ets @Entry @Component struct CalendarPickerExample { private disabledDateRange: DateRange[] = [ { start: new Date('2025-01-01'), end: new Date('2025-01-02') }, { start: new Date('2025-01-09'), end: new Date('2025-01-10') }, { start: new Date('2025-01-15'), end: new Date('2025-01-16') }, { start: new Date('2025-01-19'), end: new Date('2025-01-19') }, { start: new Date('2025-01-22'), end: new Date('2025-01-25') } ]; build() { Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { console.info("CalendarDialog.show"); CalendarPickerDialog.show({ markToday: true, disabledDateRange: this.disabledDateRange }); }) }.width('100%').margin({ top: 350 }) } } ``` ### Example 7: Customizing the Background Blur Effect This example demonstrates how to customize the background blur effect by configuring [backgroundBlurStyleOptions](#calendardialogoptions). This functionality is supported since API version 19. ```ts @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date('2025-08-05'); build() { Stack({ alignContent: Alignment.Top }) { Image($r('app.media.bg')) Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { CalendarPickerDialog.show({ selected: this.selectedDate, hintRadius: 1, backgroundColor: undefined, backgroundBlurStyle: BlurStyle.Thin, backgroundBlurStyleOptions: { colorMode: ThemeColorMode.LIGHT, adaptiveColor: AdaptiveColor.AVERAGE, scale: 1, blurOptions: { grayscale: [20, 20] }, }, }); }) }.width('100%') } } } ``` ### Example 8: Customizing the Background Effect This example demonstrates how to customize the background effect by configuring [backgroundEffect](#calendardialogoptions). This functionality is supported since API version 19. ```ts @Entry @Component struct CalendarPickerDialogExample { private selectedDate: Date = new Date('2025-08-05'); build() { Stack({ alignContent: Alignment.Top }) { Image($r('app.media.bg')) Column() { Button("Show CalendarPicker Dialog") .margin(20) .onClick(() => { CalendarPickerDialog.show({ selected: this.selectedDate, hintRadius: 1, backgroundColor: undefined, backgroundBlurStyle: BlurStyle.Thin, backgroundEffect: { radius: 60, saturation: 0, brightness: 1, color: Color.White, blurOptions: { grayscale: [20, 20] } }, }); }) }.width('100%') } } } ```