Skip to content

Commit 0e4f47f

Browse files
committed
fix: hover value logic when change panel type
1 parent e654896 commit 0e4f47f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

examples/basic.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export default () => {
1313
const [value, setValue] = React.useState<Moment | null>(defaultValue);
1414
const weekRef = React.useRef<Picker<Moment>>(null);
1515

16+
const disabledDate = (current) => {
17+
// Can not select days before today and today
18+
return current && current <= moment().endOf('day');
19+
}
20+
1621
const onSelect = (newValue: Moment) => {
1722
console.log('Select:', newValue);
1823
};
@@ -36,7 +41,7 @@ export default () => {
3641
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
3742
<div style={{ margin: '0 8px' }}>
3843
<h3>Basic</h3>
39-
<Picker<Moment> {...sharedProps} locale={zhCN} />
44+
<Picker<Moment> {...sharedProps} picker="date" value={undefined} disabledDate={disabledDate} locale={zhCN} />
4045
<Picker<Moment> {...sharedProps} locale={enUS} />
4146
</div>
4247
<div style={{ margin: '0 8px' }}>
@@ -103,7 +108,7 @@ export default () => {
103108
</div>
104109
<div style={{ margin: '0 8px' }}>
105110
<h3>Week</h3>
106-
<Picker<Moment> generateConfig={momentGenerateConfig} locale={enUS} picker="week" />
111+
<Picker<Moment> disabledDate={disabledDate} generateConfig={momentGenerateConfig} locale={enUS} picker="week" />
107112
</div>
108113
<div style={{ margin: '0 8px' }}>
109114
<h3>Quarter</h3>

src/Picker.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
357357
};
358358
}
359359

360+
const [hoverValue, onEnter, onLeave] = useHoverValue(text, {
361+
formatList,
362+
generateConfig,
363+
locale,
364+
});
365+
360366
// ============================= Panel =============================
361367
const panelProps = {
362368
// Remove `picker` & `format` here since TimePicker is little different with other panel
@@ -383,6 +389,11 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
383389
setSelectedValue(date);
384390
}}
385391
direction={direction}
392+
onPanelChange={(viewDate, mode) => {
393+
const { onPanelChange } = panelProps
394+
onLeave(true);
395+
onPanelChange?.(viewDate, mode);
396+
}}
386397
/>
387398
);
388399

@@ -445,12 +456,6 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
445456
};
446457
const popupPlacement = direction === 'rtl' ? 'bottomRight' : 'bottomLeft';
447458

448-
const [hoverValue, onEnter, onLeave] = useHoverValue(text, {
449-
formatList,
450-
generateConfig,
451-
locale,
452-
});
453-
454459
return (
455460
<PanelContext.Provider
456461
value={{

0 commit comments

Comments
 (0)