Skip to content

Commit

Permalink
fix(date-picker): fix date-picker scroll the bottom jump scrollTop th…
Browse files Browse the repository at this point in the history
…e bug (#2573)

Co-authored-by: Heising <[email protected]>
  • Loading branch information
HaixingOoO and Heising authored Nov 20, 2023
1 parent 27b1865 commit 1e59377
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Placement } from '@popperjs/core';
import useControlled from '../hooks/useControlled';
import useAnimation from '../_util/useAnimation';
import useConfig from '../hooks/useConfig';
import usePrevious from '../hooks/usePrevious';
import { TdPopupProps } from './type';
import Portal from '../common/Portal';
import useTrigger from './hooks/useTrigger';
Expand Down Expand Up @@ -70,7 +69,6 @@ const Popup = forwardRef<PopupRef, PopupProps>((originalProps, ref) => {
const { keepExpand, keepFade } = useAnimation();
const { height: windowHeight, width: windowWidth } = useWindowSize();
const [visible, onVisibleChange] = useControlled(props, 'visible', props.onVisibleChange);
const prevVisible = usePrevious(visible);

const [popupElement, setPopupElement] = useState(null);
const triggerRef = useRef(null); // 记录 trigger 元素
Expand Down Expand Up @@ -128,10 +126,10 @@ const Popup = forwardRef<PopupRef, PopupProps>((originalProps, ref) => {
// 下拉展开时更新内部滚动条
useEffect(() => {
if (!triggerRef.current) triggerRef.current = getTriggerDom();
if (prevVisible !== visible && visible) {
if (visible) {
updateScrollTop?.(contentRef.current);
}
}, [visible, prevVisible, updateScrollTop, getTriggerDom]);
}, [visible, updateScrollTop, getTriggerDom]);

function handleExited() {
!destroyOnClose && popupElement && (popupElement.style.display = 'none');
Expand Down

0 comments on commit 1e59377

Please sign in to comment.