Skip to content

Commit

Permalink
refactor: rename onCalendarChange to onSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Dec 8, 2023
1 parent a7899be commit af4707a
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/NewPicker/PickerPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,14 @@ function PickerPanel<DateType = any>(
// >>> CalendarValue
// CalendarValue is a temp value for user operation
// which will only trigger `onCalendarChange` but not `onChange`
const [calendarValue, setCalendarValue] = React.useState(mergedValue);
const updateCalendarValue = (newDate: DateType) => {
setCalendarValue(newDate);

const onInternalSelect = (newDate: DateType) => {
onSelect?.(newDate);

if (mergedMode === picker) {
// setMergedValue(newDate);
triggerChange(newDate);
}
};

React.useEffect(() => {
setCalendarValue(mergedValue);
}, [mergedValue]);

// >>> PickerValue
// PickerValue is used to control the current displaying panel
const [mergedPickerValue, setInternalPickerValue] = useMergedState(
Expand All @@ -221,7 +213,7 @@ function PickerPanel<DateType = any>(
};

const onPanelValueChange = (newVal: DateType) => {
updateCalendarValue(newVal);
onInternalSelect(newVal);
setPickerValue(newVal);

// Update mode if needed
Expand Down Expand Up @@ -285,7 +277,7 @@ function PickerPanel<DateType = any>(
// Value
pickerValue={mergedPickerValue}
onPickerValueChange={setPickerValue}
value={calendarValue}
value={mergedValue}
onChange={onPanelValueChange}
// Render
cellRender={cellRender}
Expand Down

0 comments on commit af4707a

Please sign in to comment.