Skip to content

Commit

Permalink
fix(pasttimepicker): fix onclear (#2229)
Browse files Browse the repository at this point in the history
* fix(pasttimepicker): fix onclear

* fix(pasttimepicker): fix onclear

---------

Co-authored-by: YanHui <liubai@startdt.com>
  • Loading branch information
hiker90 and YanHui authored Jul 4, 2024
1 parent ed2e137 commit 1a11b45
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/past-time-picker/PastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const PastTimePicker = (props: PastTimePickerProps) => {

const [controlledVisible, setControlledVisible] = useControlledState(popoverVisible, false);

const [timeRange, setTimeRange] = useControlledState<string | undefined>(value, undefined);
const [timeRange, setTimeRange] = useControlledState<string | undefined | null>(value, undefined);

const QUICK_MAPPING = {
'day:1,0': todayText,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -212,6 +212,11 @@ const PastTimePicker = (props: PastTimePickerProps) => {
className={className}
style={style}
onClick={() => setControlledVisible(!controlledVisible)}
onClear={(e) => {
e?.stopPropagation();
handleOnSelect(null);
restProps?.onClear?.(e);
}}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/past-time-picker/demos/PastTimePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
},
} as Meta;

const Template: Story<PastTimePickerProps> = (args) => <PastTimePicker onSelect={action('selected value:')} placeholder="时间范围" {...args} />
const Template: Story<PastTimePickerProps> = (args) => <PastTimePicker onSelect={action('selected value:')} allowClear placeholder="时间范围" {...args} />

export const Quick = Template.bind({});
Quick.args = {
Expand Down
2 changes: 1 addition & 1 deletion src/static-past-time-picker/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface StaticPastTimePickerProps extends Omit<PickerProps, 'onSelect'>
/**
* 选择完后的回调,参数为选中项的 timeRange 值
*/
onSelect?: (timeRange: string) => void;
onSelect?: (timeRange: string | null) => void;
onRangeSelect?: (dates: [Date, Date], index: number) => void;
NotAvailableToday?: boolean;
}
Expand Down

0 comments on commit 1a11b45

Please sign in to comment.