fix: should not be render default indicator when indicator value is null (#19943)

This commit is contained in:
骗你是小猫咪 2019-11-27 09:40:47 +08:00 committed by 只捱宅
parent c7810823bf
commit bed1f7775b
3 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Spin if indicator set null should not be render default indicator 1`] = `
<Spin
indicator={null}
size="default"
spinning={true}
wrapperClassName=""
>
<div
className="ant-spin ant-spin-spinning"
/>
</Spin>
`;
exports[`Spin should render custom indicator when it's set 1`] = `
<div
class="ant-spin ant-spin-spinning"

View File

@ -38,4 +38,9 @@ describe('Spin', () => {
wrapper.setProps({ spinning: true });
expect(wrapper.instance().state.spinning).toBe(true);
});
it('if indicator set null should not be render default indicator', () => {
const wrapper = mount(<Spin indicator={null} />);
expect(wrapper).toMatchSnapshot();
});
});

View File

@ -7,7 +7,7 @@ import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { tuple } from '../_util/type';
const SpinSizes = tuple('small', 'default', 'large');
export type SpinSize = (typeof SpinSizes)[number];
export type SpinSize = typeof SpinSizes[number];
export type SpinIndicator = React.ReactElement<HTMLElement>;
export interface SpinProps {
@ -33,6 +33,12 @@ let defaultIndicator: React.ReactNode = null;
function renderIndicator(prefixCls: string, props: SpinProps): React.ReactNode {
const { indicator } = props;
const dotClassName = `${prefixCls}-dot`;
// should not be render default indicator when indicator value is null
if (indicator === null) {
return null;
}
if (React.isValidElement(indicator)) {
return React.cloneElement(indicator, {
className: classNames(indicator.props.className, dotClassName),