diff --git a/examples/basic.tsx b/examples/basic.tsx index 7885a2ec1..254603acb 100644 --- a/examples/basic.tsx +++ b/examples/basic.tsx @@ -13,6 +13,11 @@ export default () => { const [value, setValue] = React.useState(defaultValue); const weekRef = React.useRef>(null); + const disabledDate = (current: Moment) => { + // Can not select days before today and today + return current && current <= moment().endOf('day'); + }; + const onSelect = (newValue: Moment) => { console.log('Select:', newValue); }; @@ -36,7 +41,7 @@ export default () => {

Basic

- {...sharedProps} locale={zhCN} /> + {...sharedProps} picker="date" value={undefined} disabledDate={disabledDate} locale={zhCN} /> {...sharedProps} locale={enUS} />
@@ -103,7 +108,7 @@ export default () => {

Week

- generateConfig={momentGenerateConfig} locale={enUS} picker="week" /> + disabledDate={disabledDate} generateConfig={momentGenerateConfig} locale={enUS} picker="week" />

Quarter

diff --git a/src/Picker.tsx b/src/Picker.tsx index 953d9894f..128348ced 100644 --- a/src/Picker.tsx +++ b/src/Picker.tsx @@ -357,6 +357,12 @@ function InnerPicker(props: PickerProps) { }; } + const [hoverValue, onEnter, onLeave] = useHoverValue(text, { + formatList, + generateConfig, + locale, + }); + // ============================= Panel ============================= const panelProps = { // Remove `picker` & `format` here since TimePicker is little different with other panel @@ -383,6 +389,11 @@ function InnerPicker(props: PickerProps) { setSelectedValue(date); }} direction={direction} + onPanelChange={(viewDate, mode) => { + const { onPanelChange } = panelProps; + onLeave(true); + onPanelChange?.(viewDate, mode); + }} /> ); @@ -445,12 +456,6 @@ function InnerPicker(props: PickerProps) { }; const popupPlacement = direction === 'rtl' ? 'bottomRight' : 'bottomLeft'; - const [hoverValue, onEnter, onLeave] = useHoverValue(text, { - formatList, - generateConfig, - locale, - }); - return (