Skip to content

Commit 2d3ba17

Browse files
authored
feat(datepicker): daterangepicker clear event (#3512)
1 parent abc177f commit 2d3ba17

4 files changed

Lines changed: 7 additions & 0 deletions

File tree

packages/components/date-picker/date-picker.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ defaultValue | Array | [] | uncontrolled property。Typescript:`DateRangeValue
8585
valueType | String | - | options: time-stamp/Date/YYYY/YYYY-MM/YYYY-MM-DD/YYYY-MM-DD HH/YYYY-MM-DD HH:mm/YYYY-MM-DD HH:mm:ss/YYYY-MM-DD HH:mm:ss:SSS | N
8686
onBlur | Function | | Typescript:`(context: { value: DateRangeValue; partial: DateRangePickerPartial; e: FocusEvent }) => void`<br/> | N
8787
onChange | Function | | Typescript:`(value: DateRangeValue, context: { dayjsValue?: Dayjs[], trigger?: DatePickerTriggerSource }) => void`<br/>[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/date-picker/type.ts)。<br/>`import { Dayjs } from 'dayjs'`<br/> | N
88+
onClear | Function | | Typescript:`(context: { e: MouseEvent }) => void`<br/>Triggered when the clear button is clicked | N
8889
onConfirm | Function | | Typescript:`(context: { date: Date[], e: MouseEvent, partial: DateRangePickerPartial }) => void`<br/> | N
8990
onFocus | Function | | Typescript:`(context: { value: DateRangeValue; partial: DateRangePickerPartial; e: FocusEvent }) => void`<br/> | N
9091
onInput | Function | | Typescript:`(context: { input: string; value: DateRangeValue; partial: DateRangePickerPartial; e: InputEvent }) => void`<br/> | N

packages/components/date-picker/date-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ defaultValue | Array | [] | 选中值。非受控属性。TS 类型:`DateRange
8484
valueType | String | - | 用于格式化日期的值,仅支持部分格式,时间戳、日期等。⚠️ `YYYYMMDD` 这种格式不支持,请勿使用,如果希望支持可以给 `dayjs` 提个 PR。注意和 `format` 的区别,`format` 仅用于处理日期在页面中呈现的格式。可选项:time-stamp/Date/YYYY/YYYY-MM/YYYY-MM-DD/YYYY-MM-DD HH/YYYY-MM-DD HH:mm/YYYY-MM-DD HH:mm:ss/YYYY-MM-DD HH:mm:ss:SSS | N
8585
onBlur | Function | | TS 类型:`(context: { value: DateRangeValue; partial: DateRangePickerPartial; e: FocusEvent }) => void`<br/>当输入框失去焦点时触发 | N
8686
onChange | Function | | TS 类型:`(value: DateRangeValue, context: { dayjsValue?: Dayjs[], trigger?: DatePickerTriggerSource }) => void`<br/>选中值发生变化时触发。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/date-picker/type.ts)。<br/>`import { Dayjs } from 'dayjs'`<br/> | N
87+
onClear | Function | | TS 类型:`(context: { e: MouseEvent }) => void`<br/>清空按钮点击时触发 | N
8788
onConfirm | Function | | TS 类型:`(context: { date: Date[], e: MouseEvent, partial: DateRangePickerPartial }) => void`<br/>如果存在“确定”按钮,则点击“确定”按钮时触发 | N
8889
onFocus | Function | | TS 类型:`(context: { value: DateRangeValue; partial: DateRangePickerPartial; e: FocusEvent }) => void`<br/>输入框获得焦点时触发 | N
8990
onInput | Function | | TS 类型:`(context: { input: string; value: DateRangeValue; partial: DateRangePickerPartial; e: InputEvent }) => void`<br/>输入框数据发生变化时触发,参数 input 表示输入内容,value 表示组件当前有效值 | N

packages/components/date-picker/hooks/useRange.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default function useRange(props: TdDateRangePickerProps) {
7676
e.stopPropagation();
7777
handlePopupInvisible();
7878
onChange([], { dayjsValue: [], trigger: 'clear' });
79+
props.onClear?.({ e });
7980
},
8081
onBlur: (newVal: string[], { e, position }) => {
8182
props.onBlur?.({ value: newVal, partial: PARTIAL_MAP[position], e });

packages/components/date-picker/type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ export interface TdDateRangePickerProps {
332332
* 选中值发生变化时触发
333333
*/
334334
onChange?: (value: DateRangeValue, context: { dayjsValue?: Dayjs[]; trigger?: DatePickerTriggerSource }) => void;
335+
/**
336+
* 清空按钮点击时触发
337+
*/
338+
onClear?: (context: { e: MouseEvent<SVGSVGElement> }) => void;
335339
/**
336340
* 如果存在“确定”按钮,则点击“确定”按钮时触发
337341
*/

0 commit comments

Comments
 (0)