Skip to content

Commit 6fd9ee5

Browse files
authored
feat(Calendar): support readonly prop (#3752)
* feat(Calendar): support readonly prop * docs(Calendar): sync api docs
1 parent 6d98209 commit 6fd9ee5

5 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/calendar/README.en-US.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ format | Function | - | Typescript:`CalendarFormatType ` `type CalendarFormatT
1515
locale-text | Object | - | Typescript:`CalendarLocaleText` `interface CalendarLocaleText {title?: string; weekdays?: string[]; monthTitle?: string; months?: string[]; confirm?: string;}`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/calendar/type.ts) | N
1616
max-date | Number | - | \- | N
1717
min-date | Number | - | \- | N
18-
switch-mode | String | none | options: none/month/year-month | N
18+
readonly | Boolean | - | `1.9.7` | N
19+
switch-mode | String | none | `1.8.2`。options: none/month/year-month | N
1920
title | String / Slot | - | [see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
2021
type | String | 'single' | options: single/multiple/range | N
2122
use-popup | Boolean | true | `0.32.0` | N
@@ -31,7 +32,7 @@ name | params | description
3132
change | `(value: timestamp)` | `0.28.0`
3233
close | `(trigger: CalendarTrigger)` | `0.34.0`[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/calendar/type.ts)。<br/>`type CalendarTrigger = 'close-btn' \| 'confirm-btn' \| 'overlay'`<br/>
3334
confirm | `(value: timestamp)` | \-
34-
panel-change | `(year: number; month: number)` | `1.8.4`
35+
panel-change | `(detail: { year: number, month: number })` | `1.8.4`
3536
scroll | `({scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY})` | `1.4.6`。triggered when scrolling
3637
select | `(value: timestamp)` | `0.28.0`
3738

src/calendar/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ format | Function | - | 用于格式化日期的函数。TS 类型:`CalendarFo
8181
locale-text | Object | - | 国际化文案。TS 类型:`CalendarLocaleText` `interface CalendarLocaleText {title?: string; weekdays?: string[]; monthTitle?: string; months?: string[]; confirm?: string;}`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/calendar/type.ts) | N
8282
max-date | Number | - | 最大可选的日期,不传则默认半年后 | N
8383
min-date | Number | - | 最小可选的日期,不传则默认今天 | N
84-
switch-mode | String | none | 切换模式。 `none` 表示水平方向平铺展示所有月份; `month` 表示支持按月切换, `year-month` 表示既按年切换,也支持按月切换。可选项:none/month/year-month | N
84+
readonly | Boolean | - | `1.9.7`。是否只读,只读状态下不能选择日期 | N
85+
switch-mode | String | none | `1.8.2`。切换模式。 `none` 表示平铺展示所有月份; `month` 表示支持按月切换, `year-month` 表示既按年切换,也支持按月切换。可选项:none/month/year-month | N
8586
title | String / Slot | - | 标题,不传默认为“请选择日期”。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
8687
type | String | 'single' | 日历的选择类型,single = 单选;multiple = 多选; range = 区间选择。可选项:single/multiple/range | N
8788
use-popup | Boolean | true | `0.32.0`。是否使用弹出层包裹日历 | N
@@ -97,7 +98,7 @@ visible | Boolean | false | 是否显示日历;`usePopup` 为 true 时有效 |
9798
change | `(value: timestamp)` | `0.28.0`。不显示 confirm-btn 时,完成选择时触发(暂不支持 type = multiple)
9899
close | `(trigger: CalendarTrigger)` | `0.34.0`。关闭按钮时触发。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/calendar/type.ts)。<br/>`type CalendarTrigger = 'close-btn' \| 'confirm-btn' \| 'overlay'`<br/>
99100
confirm | `(value: timestamp)` | 点击确认按钮时触发
100-
panel-change | `(year: number; month: number)` | `1.8.4`。切换月或年时触发(switch-mode 不为 none 时有效)
101+
panel-change | `(detail: { year: number, month: number })` | `1.8.4`。切换月或年时触发(switch-mode 不为 none 时有效)
101102
scroll | `({scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY})` | `1.4.6`。滚动时触发
102103
select | `(value: timestamp)` | `0.28.0`。点击日期时触发
103104

src/calendar/calendar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ export default class Calendar extends SuperComponent {
232232
},
233233

234234
handleSelect(e) {
235+
const { readonly } = this.properties;
235236
const { date, year, month } = e.currentTarget.dataset;
236237

237-
if (date.type === 'disabled') return;
238+
if (date.type === 'disabled' || readonly) return;
238239

239240
const rawValue = this.base.select({ cellType: date.type, year, month, date: date.day });
240241

src/calendar/props.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ const props: TdCalendarProps = {
3737
minDate: {
3838
type: Number,
3939
},
40-
/** 切换模式。 `none` 表示水平方向平铺展示所有月份; `month` 表示支持按月切换, `year-month` 表示既按年切换,也支持按月切换 */
40+
/** 是否只读,只读状态下不能选择日期 */
41+
readonly: {
42+
type: Boolean,
43+
},
44+
/** 切换模式。 `none` 表示平铺展示所有月份; `month` 表示支持按月切换, `year-month` 表示既按年切换,也支持按月切换 */
4145
switchMode: {
4246
type: String,
4347
value: 'none',

src/calendar/type.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ export interface TdCalendarProps {
6060
value?: number;
6161
};
6262
/**
63-
* 切换模式。 `none` 表示水平方向平铺展示所有月份; `month` 表示支持按月切换, `year-month` 表示既按年切换,也支持按月切换
63+
* 是否只读,只读状态下不能选择日期
64+
*/
65+
readonly?: {
66+
type: BooleanConstructor;
67+
value?: boolean;
68+
};
69+
/**
70+
* 切换模式。 `none` 表示平铺展示所有月份; `month` 表示支持按月切换, `year-month` 表示既按年切换,也支持按月切换
6471
* @default none
6572
*/
6673
switchMode?: {

0 commit comments

Comments
 (0)