fix: fix float-button findDOMNode error (#48865)

This commit is contained in:
Wanpan 2024-05-10 16:28:25 +08:00 committed by GitHub
parent 1f39811047
commit c9f7f5d8e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import React, { useContext, useEffect, useState } from 'react';
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
import classNames from 'classnames';
import CSSMotion from 'rc-motion';
import { composeRef } from 'rc-util/es/ref';
import getScroll from '../_util/getScroll';
import scrollTo from '../_util/scrollTo';
@ -87,9 +88,9 @@ const BackTop = React.forwardRef<FloatButtonRef, BackTopProps>((props, ref) => {
return (
<CSSMotion visible={visible} motionName={`${rootPrefixCls}-fade`}>
{({ className: motionClassName }) => (
{({ className: motionClassName }, setRef) => (
<FloatButton
ref={internalRef}
ref={composeRef(internalRef, setRef)}
{...contentProps}
onClick={scrollToTop}
className={classNames(className, motionClassName)}

View File

@ -8,6 +8,8 @@ import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
const { BackTop } = FloatButton;
describe('BackTop', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
beforeEach(() => {
jest.useFakeTimers();
});
@ -55,7 +57,6 @@ describe('BackTop', () => {
});
it('no error when BackTop work', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<BackTop visibilityHeight={0} />);
expect(errSpy).not.toHaveBeenCalled();
errSpy.mockRestore();