• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CalendarPicker
2
3The **\<CalendarPicker>** component provides a drop-down calendar for users to select a date.
4
5>  **NOTE**
6>
7>  This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## Child Components
11
12Not supported
13
14## APIs
15
16CalendarPicker(options?: CalendarOptions)
17
18## Attributes
19
20In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
21
22| Name         | Type          | Description                               |
23| ----------- | ----------- | --------------------------------- |
24| edgeAlign | alignType: [CalendarAlign](#calendaralign), offset?: [Offset](ts-types.md#offset) | How the picker is aligned with the entry component.<br>- **alignType**: alignment type.<br>Default value: **CalendarAlign.END**<br>- **offset**: offset of the picker relative to the entry component after alignment based on the specified alignment type.<br>Default value: **{dx: 0, dy: 0}.**|
25| textStyle | [PickerTextStyle](./ts-basic-components-datepicker.md#pickertextstyle10) | Font color, font size, and font width in the entry area.                      |
26## Events
27
28In addition to the [universal events](ts-universal-events-click.md), the following events are supported.
29
30| Name                                     | Description              |
31| ----------------------------------------- | ---------------------- |
32| onChange(callback: (value: Date) => void) | Triggered when a date is selected.<br>**value**: selected date value|
33
34##  CalendarOptions
35
36| Name     | Type      | Mandatory       | Description                             |
37| ----------- | ---------- | ------| --------------------------------- |
38| hintRadius | number \| [Resource](ts-types.md#resource) | No   | Style of the background of the selected state.<br>Default value: The background is a circle.<br>**NOTE**<br>If the value is **0**, the background is a rectangle with square corners. If the value is in the 0–16 range, the background is a rectangle with rounded corners. If the value is equal to or greater than 16, the background is a circle.|
39| selected | Date | No   | Date of the selected item.<br>Default value: current system date<br>|
40
41## CalendarAlign
42
43Since API version 9, this API is supported in ArkTS widgets.
44
45| Name  | Description                    |
46| ------ | ------------------------ |
47| START  | The picker is left aligned with the entry component.  |
48| CENTER | The picker is center aligned with the entry component.|
49| END    | The picker is right aligned with the entry component.  |
50
51## Example
52
53```ts
54// xxx.ets
55@Entry
56@Component
57struct CalendarPickerExample {
58  private selectedDate: Date = new Date()
59  build() {
60    Column() {
61      Text('Calendar date picker').fontSize(30)
62      Column() {
63        CalendarPicker({ hintRadius: 10, selected: this.selectedDate })
64          .edgeAlign(CalendarAlign.END)
65          .textStyle({ color: "#ff182431", font: { size: 20, weight: FontWeight.Normal } })
66          .margin(10)
67          .onChange((value) => {
68            console.info("CalendarPicker onChange:" + JSON.stringify(value))
69          })
70      }.alignItems(HorizontalAlign.End).width("100%")
71    }.width('100%').margin({top:350})
72  }
73}
74```
75
76![CalendarPicker](figures/CalendarPicker.gif)
77