mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
chore: add warning of tip with spin (#42293)
This commit is contained in:
parent
4207b71aa8
commit
31852e1b65
@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import { waitFakeTimer } from '../../../tests/utils';
|
||||
import React from 'react';
|
||||
import Spin from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import { waitFakeTimer } from '../../../tests/utils';
|
||||
|
||||
describe('Spin', () => {
|
||||
mountTest(Spin);
|
||||
@ -52,4 +52,15 @@ describe('Spin', () => {
|
||||
const { container } = render(<Spin>{0}</Spin>);
|
||||
expect(container.querySelector('.ant-spin-container')?.textContent).toBe('0');
|
||||
});
|
||||
|
||||
it('warning tip without nest', () => {
|
||||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
const { container } = render(<Spin tip="Not Show" />);
|
||||
expect(container.querySelector('.ant-spin-text')).toBeFalsy();
|
||||
|
||||
expect(errSpy).toHaveBeenCalledWith('Warning: [antd: Spin] `tip` only work in nest pattern.');
|
||||
|
||||
errSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
@ -1,10 +1,11 @@
|
||||
import classNames from 'classnames';
|
||||
import { debounce } from 'throttle-debounce';
|
||||
import omit from 'rc-util/lib/omit';
|
||||
import * as React from 'react';
|
||||
import { debounce } from 'throttle-debounce';
|
||||
import { cloneElement, isValidElement } from '../_util/reactNode';
|
||||
import warning from '../_util/warning';
|
||||
import type { ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import { cloneElement, isValidElement } from '../_util/reactNode';
|
||||
import useStyle from './style/index';
|
||||
|
||||
const SpinSizes = ['small', 'default', 'large'] as const;
|
||||
@ -108,6 +109,10 @@ const Spin: React.FC<SpinClassProps> = (props) => {
|
||||
|
||||
const isNestedPattern = React.useMemo<boolean>(() => typeof children !== 'undefined', [children]);
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
warning(!tip || isNestedPattern, 'Spin', '`tip` only work in nest pattern.');
|
||||
}
|
||||
|
||||
const { direction } = React.useContext<ConfigConsumerProps>(ConfigContext);
|
||||
|
||||
const spinClassName = classNames(
|
||||
@ -140,7 +145,7 @@ const Spin: React.FC<SpinClassProps> = (props) => {
|
||||
aria-busy={spinning}
|
||||
>
|
||||
{renderIndicator(prefixCls, props)}
|
||||
{tip ? <div className={`${prefixCls}-text`}>{tip}</div> : null}
|
||||
{tip && isNestedPattern ? <div className={`${prefixCls}-text`}>{tip}</div> : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user