From 9f3e5c5f6d9017e8900074d825b2008712bc1558 Mon Sep 17 00:00:00 2001 From: YanHui Date: Wed, 3 Jul 2024 18:50:09 +0800 Subject: [PATCH 1/5] fix(pasttimepicker): fix onclear --- src/past-time-picker/PastTimePicker.tsx | 5 +++++ src/past-time-picker/demos/PastTimePicker.stories.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index c517e56bb9..1e3dbe1d8b 100644 --- a/src/past-time-picker/PastTimePicker.tsx +++ b/src/past-time-picker/PastTimePicker.tsx @@ -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 = { From 0ab83ab75d7870e2ea75aca29221ad95543f689c Mon Sep 17 00:00:00 2001 From: YanHui Date: Thu, 4 Jul 2024 10:08:22 +0800 Subject: [PATCH 2/5] fix(pasttimepicker): fix onclear --- src/past-time-picker/PastTimePicker.tsx | 6 +++--- src/static-past-time-picker/interfaces.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index 1e3dbe1d8b..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); @@ -213,7 +213,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { style={style} onClick={() => setControlledVisible(!controlledVisible)} onClear={(e) => { - e.stopPropagation(); + e?.stopPropagation(); handleOnSelect(null); restProps?.onClear?.(e); }} 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; } From 9e7fc5c3df1d6c4265075d6da9cfa1aaf1ed559e Mon Sep 17 00:00:00 2001 From: YanHui Date: Thu, 4 Jul 2024 10:29:56 +0800 Subject: [PATCH 3/5] fix(pasttimepicker): fix onclear --- .vscode/settings.json | 4 ++-- src/past-time-picker/PastTimePicker.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0cc071de7f..c9e4cab15c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,8 +5,8 @@ "editor.defaultFormatter": "esbenp.prettier-vscode" }, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - "source.fixAll.stylelint": true + "source.fixAll.eslint": "explicit", + "source.fixAll.stylelint": "explicit" }, //eslint -----settings start----- diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index bb4a869988..042f678e6a 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, @@ -171,7 +171,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { }; const handleOnSelect = (currentValue: string | null) => { - setTimeRange(currentValue, true); + setTimeRange(currentValue ?? undefined, true); setControlledVisible(false); onSelect?.(currentValue); }; From 2ff2512e5ff9013b647fd5c67653274105dfe9ad Mon Sep 17 00:00:00 2001 From: YanHui Date: Thu, 4 Jul 2024 10:48:33 +0800 Subject: [PATCH 4/5] fix(pasttimepicker): fix onclear --- .vscode/settings.json | 51 ------------------------- src/past-time-picker/PastTimePicker.tsx | 2 +- 2 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index c9e4cab15c..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "editor.formatOnSave": true, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "[javascript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit", - "source.fixAll.stylelint": "explicit" - }, - - //eslint -----settings start----- - - "eslint.packageManager": "yarn", - "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], - - //eslint -----settings end----- - - //prettier -----settings start----- - - "prettier.useEditorConfig": false, - "prettier.requireConfig": true, - - //prettier -----settings end----- - //pretier -----settings end----- - - //stylelint -----settings start----- - - // 防止编辑器内置linter与插件冲突设置 - "css.validate": false, - "less.validate": false, - "scss.validate": false, - "stylelint.enable": true, - "stylelint.packageManager": "yarn", - "stylelint.validate": [ - "css", - "html", - "less", - "markdown", - "postcss", - "sass", - "scss", - "source.css.styled", - "styled-css", - "sugarss", - "svelte" - ], - "typescript.tsdk": "node_modules/typescript/lib" - - //stylelint -----settings end----- -} diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index 228982341c..c841da3738 100644 --- a/src/past-time-picker/PastTimePicker.tsx +++ b/src/past-time-picker/PastTimePicker.tsx @@ -171,7 +171,7 @@ const PastTimePicker = (props: PastTimePickerProps) => { }; const handleOnSelect = (currentValue: string | null) => { - setTimeRange(currentValue ?? undefined, true); + setTimeRange((!currentValue ? undefined : currentValue) as string | undefined, true); setControlledVisible(false); onSelect?.(currentValue); }; From eed2396b9ede35646d977240a2e73b5dcc026186 Mon Sep 17 00:00:00 2001 From: YanHui Date: Thu, 4 Jul 2024 10:55:18 +0800 Subject: [PATCH 5/5] fix(pasttimepicker): fix onclear --- src/past-time-picker/PastTimePicker.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/past-time-picker/PastTimePicker.tsx b/src/past-time-picker/PastTimePicker.tsx index c841da3738..b0a5e4c3d7 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,