From af1a828b18adb5be0a0e50930815705f7e13c488 Mon Sep 17 00:00:00 2001 From: Chuck Date: Fri, 5 May 2023 15:09:12 +0800 Subject: [PATCH 1/3] fix: DatePicker cannot be cleared by set undefined --- packages/zarm/src/date-picker-view/DatePickerView.tsx | 1 - packages/zarm/src/date-select/DateSelect.tsx | 2 +- packages/zarm/src/date-select/interface.ts | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/zarm/src/date-picker-view/DatePickerView.tsx b/packages/zarm/src/date-picker-view/DatePickerView.tsx index b9fce999c..aaa952b75 100644 --- a/packages/zarm/src/date-picker-view/DatePickerView.tsx +++ b/packages/zarm/src/date-picker-view/DatePickerView.tsx @@ -43,7 +43,6 @@ const DatePickerView = React.forwardRef { - if (props.value === undefined) return; if (isEqual(props.value, innerValue)) return; setInnerValue(props.value); }, [props.value]); diff --git a/packages/zarm/src/date-select/DateSelect.tsx b/packages/zarm/src/date-select/DateSelect.tsx index 88bc5a277..097a9998b 100644 --- a/packages/zarm/src/date-select/DateSelect.tsx +++ b/packages/zarm/src/date-select/DateSelect.tsx @@ -51,7 +51,6 @@ const DateSelect: React.FC = (props) => { const bem = createBEM('date-select', { prefixCls }); React.useEffect(() => { - if (props.value === undefined) return; if (isEqual(value, innerValue)) return; setInnerValue(value); }, [value]); @@ -68,6 +67,7 @@ const DateSelect: React.FC = (props) => { }); onConfirm?.(changedValue, changedItems); + onChange?.(changedValue, changedItems); }; const handleCancel = () => { diff --git a/packages/zarm/src/date-select/interface.ts b/packages/zarm/src/date-select/interface.ts index be1ec3151..9137dc846 100644 --- a/packages/zarm/src/date-select/interface.ts +++ b/packages/zarm/src/date-select/interface.ts @@ -5,4 +5,5 @@ export interface BaseDateSelectProps extends Omit React.ReactNode; + onChange?: (value: Date, items: PickerColumnItem[]) => void; } From a4e408a05f623f00684aa1d0207280b13866b17a Mon Sep 17 00:00:00 2001 From: Chuck Date: Fri, 5 May 2023 15:14:01 +0800 Subject: [PATCH 2/3] feat: DateSelect cleanup demo --- packages/zarm/src/date-picker/demo.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/zarm/src/date-picker/demo.md b/packages/zarm/src/date-picker/demo.md index da25d6b29..c07b8e9e8 100644 --- a/packages/zarm/src/date-picker/demo.md +++ b/packages/zarm/src/date-picker/demo.md @@ -251,14 +251,26 @@ ReactDOM.render(, mountNode); ```jsx import { useState } from 'react'; -import { Toast, List, DateSelect } from 'zarm'; +import { Toast, List, DateSelect, Button } from 'zarm'; const Demo = () => { + const [value, setValue] = useState(new Date()); return ( - + { + setValue(undefined); + }} + >清除 + } + > console.log('DateSelect onChange', value, items)} + value={value} + onChange={(value, items) => {console.log('DateSelect onChange', value, items); setValue(value);}} onConfirm={(value, items) => { Toast.show(value.toLocaleString()); console.log('DateSelect onConfirm', value, items); From d04f422b9852ed386d697338d4d0b0b732f80465 Mon Sep 17 00:00:00 2001 From: Chuck Date: Wed, 10 May 2023 14:23:50 +0800 Subject: [PATCH 3/3] refactor: PR review #1100 --- packages/zarm/src/date-picker/demo.md | 3 ++- packages/zarm/src/date-select/DateSelect.tsx | 2 -- packages/zarm/src/date-select/interface.ts | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/zarm/src/date-picker/demo.md b/packages/zarm/src/date-picker/demo.md index c07b8e9e8..f41a5df3b 100644 --- a/packages/zarm/src/date-picker/demo.md +++ b/packages/zarm/src/date-picker/demo.md @@ -270,8 +270,9 @@ const Demo = () => { > {console.log('DateSelect onChange', value, items); setValue(value);}} + onChange={(value, items) => {console.log('DateSelect onChange', value, items);}} onConfirm={(value, items) => { + setValue(value); Toast.show(value.toLocaleString()); console.log('DateSelect onConfirm', value, items); }} diff --git a/packages/zarm/src/date-select/DateSelect.tsx b/packages/zarm/src/date-select/DateSelect.tsx index 097a9998b..3d3add8f1 100644 --- a/packages/zarm/src/date-select/DateSelect.tsx +++ b/packages/zarm/src/date-select/DateSelect.tsx @@ -37,7 +37,6 @@ const DateSelect: React.FC = (props) => { filter, renderLabel, displayRender = (items) => items?.map((item) => item && item.label), - onChange, onCancel, onConfirm, ...rest @@ -67,7 +66,6 @@ const DateSelect: React.FC = (props) => { }); onConfirm?.(changedValue, changedItems); - onChange?.(changedValue, changedItems); }; const handleCancel = () => { diff --git a/packages/zarm/src/date-select/interface.ts b/packages/zarm/src/date-select/interface.ts index 9137dc846..be1ec3151 100644 --- a/packages/zarm/src/date-select/interface.ts +++ b/packages/zarm/src/date-select/interface.ts @@ -5,5 +5,4 @@ export interface BaseDateSelectProps extends Omit React.ReactNode; - onChange?: (value: Date, items: PickerColumnItem[]) => void; }