mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-28 07:23:46 +08:00
chore: remove rc-util/addEventListener (#39923)
* chore: remove rc-utils/addEventListener * fix * fix
This commit is contained in:
parent
06de226d36
commit
a80b39d34d
@ -1,5 +1,4 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import Affix from '../affix';
|
import Affix from '../affix';
|
||||||
import type { ConfigConsumerProps } from '../config-provider';
|
import type { ConfigConsumerProps } from '../config-provider';
|
||||||
@ -297,10 +296,10 @@ const AnchorContent: React.FC<InternalAnchorProps> = (props) => {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const scrollContainer = getCurrentContainer();
|
const scrollContainer = getCurrentContainer();
|
||||||
const scrollEvent = addEventListener(scrollContainer, 'scroll', handleScroll);
|
|
||||||
handleScroll();
|
handleScroll();
|
||||||
|
scrollContainer?.addEventListener('scroll', handleScroll);
|
||||||
return () => {
|
return () => {
|
||||||
scrollEvent?.remove();
|
scrollContainer?.removeEventListener('scroll', handleScroll);
|
||||||
};
|
};
|
||||||
}, [dependencyListItem]);
|
}, [dependencyListItem]);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
|
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import CSSMotion from 'rc-motion';
|
import CSSMotion from 'rc-motion';
|
||||||
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
|
||||||
import omit from 'rc-util/lib/omit';
|
import omit from 'rc-util/lib/omit';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import type { ConfigConsumerProps } from '../config-provider';
|
import type { ConfigConsumerProps } from '../config-provider';
|
||||||
@ -36,7 +35,6 @@ const BackTop: React.FC<BackTopProps> = (props) => {
|
|||||||
const [visible, setVisible] = React.useState<boolean>(visibilityHeight === 0);
|
const [visible, setVisible] = React.useState<boolean>(visibilityHeight === 0);
|
||||||
|
|
||||||
const ref = React.useRef<HTMLDivElement>(null);
|
const ref = React.useRef<HTMLDivElement>(null);
|
||||||
const scrollEvent = React.useRef<ReturnType<typeof addEventListener> | null>(null);
|
|
||||||
|
|
||||||
const getDefaultTarget = (): HTMLElement | Document | Window =>
|
const getDefaultTarget = (): HTMLElement | Document | Window =>
|
||||||
ref.current && ref.current.ownerDocument ? ref.current.ownerDocument : window;
|
ref.current && ref.current.ownerDocument ? ref.current.ownerDocument : window;
|
||||||
@ -48,22 +46,18 @@ const BackTop: React.FC<BackTopProps> = (props) => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const bindScrollEvent = () => {
|
|
||||||
const getTarget = target || getDefaultTarget;
|
|
||||||
const container = getTarget();
|
|
||||||
scrollEvent.current = addEventListener(container, 'scroll', handleScroll);
|
|
||||||
handleScroll({ target: container });
|
|
||||||
};
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
warning(false, 'BackTop', '`BackTop` is deprecated, please use `FloatButton.BackTop` instead.');
|
warning(false, 'BackTop', '`BackTop` is deprecated, please use `FloatButton.BackTop` instead.');
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
bindScrollEvent();
|
const getTarget = target || getDefaultTarget;
|
||||||
|
const container = getTarget();
|
||||||
|
handleScroll({ target: container });
|
||||||
|
container?.addEventListener('scroll', handleScroll);
|
||||||
return () => {
|
return () => {
|
||||||
handleScroll.cancel();
|
handleScroll.cancel();
|
||||||
scrollEvent.current?.remove();
|
container?.removeEventListener('scroll', handleScroll);
|
||||||
};
|
};
|
||||||
}, [target]);
|
}, [target]);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
|
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import CSSMotion from 'rc-motion';
|
import CSSMotion from 'rc-motion';
|
||||||
import addEventListener from 'rc-util/lib/Dom/addEventListener';
|
|
||||||
import React, { memo, useContext, useEffect, useRef, useState } from 'react';
|
import React, { memo, useContext, useEffect, useRef, useState } from 'react';
|
||||||
import FloatButton, { floatButtonPrefixCls } from './FloatButton';
|
import FloatButton, { floatButtonPrefixCls } from './FloatButton';
|
||||||
import type { ConfigConsumerProps } from '../config-provider';
|
import type { ConfigConsumerProps } from '../config-provider';
|
||||||
@ -30,7 +29,6 @@ const BackTop: React.FC<BackTopProps> = (props) => {
|
|||||||
const [visible, setVisible] = useState<boolean>(visibilityHeight === 0);
|
const [visible, setVisible] = useState<boolean>(visibilityHeight === 0);
|
||||||
|
|
||||||
const ref = useRef<HTMLAnchorElement | HTMLButtonElement>(null);
|
const ref = useRef<HTMLAnchorElement | HTMLButtonElement>(null);
|
||||||
const scrollEvent = useRef<ReturnType<typeof addEventListener> | null>(null);
|
|
||||||
|
|
||||||
const getDefaultTarget = (): HTMLElement | Document | Window =>
|
const getDefaultTarget = (): HTMLElement | Document | Window =>
|
||||||
ref.current && ref.current.ownerDocument ? ref.current.ownerDocument : window;
|
ref.current && ref.current.ownerDocument ? ref.current.ownerDocument : window;
|
||||||
@ -42,18 +40,14 @@ const BackTop: React.FC<BackTopProps> = (props) => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const bindScrollEvent = () => {
|
useEffect(() => {
|
||||||
const getTarget = target || getDefaultTarget;
|
const getTarget = target || getDefaultTarget;
|
||||||
const container = getTarget();
|
const container = getTarget();
|
||||||
scrollEvent.current = addEventListener(container, 'scroll', handleScroll);
|
|
||||||
handleScroll({ target: container });
|
handleScroll({ target: container });
|
||||||
};
|
container?.addEventListener('scroll', handleScroll);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
bindScrollEvent();
|
|
||||||
return () => {
|
return () => {
|
||||||
handleScroll.cancel();
|
handleScroll.cancel();
|
||||||
scrollEvent.current?.remove();
|
container?.removeEventListener('scroll', handleScroll);
|
||||||
};
|
};
|
||||||
}, [target]);
|
}, [target]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user