From 69718b0b2753d80fa1581e55d702fef6abe98a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 16 Jan 2024 14:06:18 +0800 Subject: [PATCH 1/7] chore: defaultPickerValue working --- docs/examples/debug.tsx | 4 +++- src/PickerInput/Popup/index.tsx | 17 +++++++++++------ src/PickerInput/RangePicker.tsx | 1 + src/PickerInput/SinglePicker.tsx | 1 + tests/picker.spec.tsx | 5 +++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/examples/debug.tsx b/docs/examples/debug.tsx index 95b3dda2a..2ae21c394 100644 --- a/docs/examples/debug.tsx +++ b/docs/examples/debug.tsx @@ -155,8 +155,10 @@ export default () => { // disabledMinutes: () => [0, 1, 2, 3, 4, 5], // disabledSeconds: () => [0, 1, 2, 3, 4, 5], // })} + defaultOpenValue={dayjs()} open - picker="time" + // picker="time" + showTime ref={singleRef} suffixIcon="🧶" // showTime={{ diff --git a/src/PickerInput/Popup/index.tsx b/src/PickerInput/Popup/index.tsx index 37c56a7cd..7832779cc 100644 --- a/src/PickerInput/Popup/index.tsx +++ b/src/PickerInput/Popup/index.tsx @@ -25,6 +25,9 @@ export interface PopupProps boolean; @@ -60,6 +63,7 @@ export default function Popup(props: PopupProps(props: PopupProps filterEmpty(toArray(value)), [value]); - const isTimePicker = picker === 'time'; - const isEmptyValue = !valueList.length; + const isTimePickerEmptyValue = picker === 'time' && !valueList.length && pickerAsValue; const footerSubmitValue = React.useMemo(() => { - if (isTimePicker && isEmptyValue) { + if (isTimePickerEmptyValue) { return filterEmpty([pickerValue]); } return valueList; - }, [isTimePicker, valueList, isEmptyValue, pickerValue]); + }, [isTimePickerEmptyValue, valueList, pickerValue]); + + const popupPanelValue = isTimePickerEmptyValue ? pickerValue : valueList; const disableSubmit = React.useMemo(() => { // Empty is invalid @@ -122,7 +127,7 @@ export default function Popup(props: PopupProps { // For TimePicker, we will additional trigger the value update - if (isTimePicker && isEmptyValue) { + if (isTimePickerEmptyValue) { onSelect(pickerValue); } @@ -140,7 +145,7 @@ export default function Popup(props: PopupProps
- +