From 08bc0aea0b34f8eb3b6b0a9bb8fe482c560f5da1 Mon Sep 17 00:00:00 2001 From: JOJO <46063163+Ricinix@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:19:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20date=20picker=20Paginatio?= =?UTF-8?q?nMini=20select=20(#2587)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JOJO <1> --- src/date-picker/DatePicker.tsx | 46 ++++++++++++++------------ src/date-picker/panel/PanelContent.tsx | 3 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/date-picker/DatePicker.tsx b/src/date-picker/DatePicker.tsx index c9ae371e13..c334f6e823 100644 --- a/src/date-picker/DatePicker.tsx +++ b/src/date-picker/DatePicker.tsx @@ -109,28 +109,30 @@ const DatePicker = forwardRef((originalProps, r } } // 头部快速切换 - const onJumperClick = React.useCallback(({ trigger }) => { - const monthCountMap = { date: 1, week: 1, month: 12, quarter: 12, year: 120 }; - const monthCount = monthCountMap[mode] || 0; - - const current = new Date(year, month); - - let next = null; - if (trigger === 'prev') { - next = subtractMonth(current, monthCount); - } else if (trigger === 'current') { - next = new Date(); - } else if (trigger === 'next') { - next = addMonth(current, monthCount); - } - - const nextYear = next.getFullYear(); - const nextMonth = next.getMonth(); - - setYear(nextYear); - setMonth(nextMonth); - // eslint-disable-next-line - }, []); + const onJumperClick = React.useCallback( + ({ trigger }) => { + const monthCountMap = { date: 1, week: 1, month: 12, quarter: 12, year: 120 }; + const monthCount = monthCountMap[mode] || 0; + + const current = new Date(year, month); + + let next = null; + if (trigger === 'prev') { + next = subtractMonth(current, monthCount); + } else if (trigger === 'current') { + next = new Date(); + } else if (trigger === 'next') { + next = addMonth(current, monthCount); + } + + const nextYear = next.getFullYear(); + const nextMonth = next.getMonth(); + + setYear(nextYear); + setMonth(nextMonth); + }, + [year, month, mode, setYear, setMonth], + ); // timePicker 点击 function onTimePickerChange(val: string) { diff --git a/src/date-picker/panel/PanelContent.tsx b/src/date-picker/panel/PanelContent.tsx index 79e30cfc54..66288ec5d9 100644 --- a/src/date-picker/panel/PanelContent.tsx +++ b/src/date-picker/panel/PanelContent.tsx @@ -82,8 +82,7 @@ export default function PanelContent(props: PanelContentProps) { ({ trigger }) => { onJumperClick?.({ trigger, partial }); }, - // eslint-disable-next-line - [partial], + [partial, onJumperClick], ); return (