Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions packages/rc-ui-lib/src/datetime-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
useImperativeHandle,
useMemo,
useRef,
useState,
memo,
useCallback,
} from 'react';

Expand Down Expand Up @@ -35,7 +35,7 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
date = props.minDate;
}

date = Math.max(date, props.minDate.getTime());
date = Math.max(new Date(date).getTime(), props.minDate.getTime());
date = Math.min(date, props.maxDate.getTime());

return new Date(date);
Expand All @@ -44,6 +44,7 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
const pickerRef = useRef<PickerInstance>(null);
const [currentDate, setCurrentDate, currentDateRef] = useRefState(formatValue(value));


const getBoundary = (type: 'max' | 'min', dateValue: Date) => {
const boundary = props[`${type}Date`];
const year = boundary.getFullYear();
Expand Down Expand Up @@ -245,15 +246,15 @@ const DatePicker = forwardRef<DateTimePickerInstance, DatePickerProps>((props, r
props.onConfirm?.(currentDate);
};

useMount(() => {
setTimeout(() => {
if (pickerRef.current) {
const indexes = pickerRef.current?.getIndexes();
const nextValue = updateInnerValue(indexes);
setCurrentDate(nextValue);
}
}, 0);
});
// useMount(() => {
// setTimeout(() => {
// if (pickerRef.current) {
// const indexes = pickerRef.current?.getIndexes();
// const nextValue = updateInnerValue(indexes);
// setCurrentDate(nextValue);
// }
// }, 0);
// });

useEffect(() => {
updateColumnValue();
Expand Down Expand Up @@ -296,4 +297,4 @@ DatePicker.defaultProps = {

DatePicker.displayName = 'DatePicker';

export default DatePicker;
export default memo(DatePicker);
4 changes: 2 additions & 2 deletions packages/rc-ui-lib/src/hooks/use-ref-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default function useRefState<T>(
const setRefState = useCallback(
(patch) => {
setState((prevState) => {
// eslint-disable-next-line no-return-assign
return (ref.current = isFunction(patch) ? patch(prevState) : patch);
// 仅判断 patch 是否是函数
return isFunction(patch) ? patch(prevState) : patch;
});
},
[state],
Expand Down
Loading