From 1a11b459030f1a3e365ad16402b19061cb782d0a Mon Sep 17 00:00:00 2001 From: hiker90 Date: Thu, 4 Jul 2024 10:11:38 +0800 Subject: [PATCH] fix(pasttimepicker): fix onclear (#2229) * fix(pasttimepicker): fix onclear * fix(pasttimepicker): fix onclear --------- Co-authored-by: YanHui --- src/past-time-picker/PastTimePicker.tsx | 9 +++++++-- src/past-time-picker/demos/PastTimePicker.stories.tsx | 2 +- src/static-past-time-picker/interfaces.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index c517e56bb9..bb4a869988 100644 --- a/src/past-time-picker/PastTimePicker.tsx +++ b/src/past-time-picker/PastTimePicker.tsx @@ -83,7 +83,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { const [controlledVisible, setControlledVisible] = useControlledState(popoverVisible, false); - const [timeRange, setTimeRange] = useControlledState(value, undefined); + const [timeRange, setTimeRange] = useControlledState(value, undefined); const QUICK_MAPPING = { 'day:1,0': todayText, @@ -170,7 +170,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { return defaultString; }; - const handleOnSelect = (currentValue: string) => { + const handleOnSelect = (currentValue: string | null) => { setTimeRange(currentValue, true); setControlledVisible(false); onSelect?.(currentValue); @@ -212,6 +212,11 @@ const PastTimePicker = (props: PastTimePickerProps) => { className={className} style={style} onClick={() => setControlledVisible(!controlledVisible)} + onClear={(e) => { + e?.stopPropagation(); + handleOnSelect(null); + restProps?.onClear?.(e); + }} /> ); } diff --git a/src/past-time-picker/demos/PastTimePicker.stories.tsx b/src/past-time-picker/demos/PastTimePicker.stories.tsx index c4696988f7..03eddcae40 100644 --- a/src/past-time-picker/demos/PastTimePicker.stories.tsx +++ b/src/past-time-picker/demos/PastTimePicker.stories.tsx @@ -20,7 +20,7 @@ export default { }, } as Meta; -const Template: Story = (args) => +const Template: Story = (args) => export const Quick = Template.bind({}); Quick.args = { diff --git a/src/static-past-time-picker/interfaces.ts b/src/static-past-time-picker/interfaces.ts index ce9a1e1d12..dc16b89dab 100644 --- a/src/static-past-time-picker/interfaces.ts +++ b/src/static-past-time-picker/interfaces.ts @@ -58,7 +58,7 @@ export interface StaticPastTimePickerProps extends Omit /** * 选择完后的回调,参数为选中项的 timeRange 值 */ - onSelect?: (timeRange: string) => void; + onSelect?: (timeRange: string | null) => void; onRangeSelect?: (dates: [Date, Date], index: number) => void; NotAvailableToday?: boolean; }