From bed1f7775b2ceb52be6da84cf6106ed7a1a29c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=97=E4=BD=A0=E6=98=AF=E5=B0=8F=E7=8C=AB=E5=92=AA?= Date: Wed, 27 Nov 2019 09:40:47 +0800 Subject: [PATCH] fix: should not be render default indicator when indicator value is null (#19943) --- .../spin/__tests__/__snapshots__/index.test.js.snap | 13 +++++++++++++ components/spin/__tests__/index.test.js | 5 +++++ components/spin/index.tsx | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/components/spin/__tests__/__snapshots__/index.test.js.snap b/components/spin/__tests__/__snapshots__/index.test.js.snap index 73e2f59bed..0485c9e095 100644 --- a/components/spin/__tests__/__snapshots__/index.test.js.snap +++ b/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`] = ` + +
+ +`; + exports[`Spin should render custom indicator when it's set 1`] = `
{ 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(); + expect(wrapper).toMatchSnapshot(); + }); }); diff --git a/components/spin/index.tsx b/components/spin/index.tsx index f072491a11..3f07daea93 100644 --- a/components/spin/index.tsx +++ b/components/spin/index.tsx @@ -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; 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),