Skip to content

Commit

Permalink
fix: should not be render default indicator when indicator value is n…
Browse files Browse the repository at this point in the history
…ull (#19943)
  • Loading branch information
shaodahong authored and orzyyyy committed Nov 27, 2019
1 parent c781082 commit bed1f77
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions components/spin/__tests__/__snapshots__/index.test.js.snap
@@ -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"
Expand Down
5 changes: 5 additions & 0 deletions components/spin/__tests__/index.test.js
Expand Up @@ -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();
});
});
8 changes: 7 additions & 1 deletion components/spin/index.tsx
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down

0 comments on commit bed1f77

Please sign in to comment.