fix: spin classname undefined

pull/2682/head
tanjinzhou 2020-08-03 18:20:16 +08:00
parent ed1c0147d4
commit 64147e7744
6 changed files with 19 additions and 29 deletions

@ -1 +1 @@
Subproject commit e03b6665dabc7b2d464ab9c7f44de66702ca1727 Subproject commit d76dd882c7b266a479533515b428c90b5630a92a

View File

@ -2,7 +2,7 @@ import { inject, cloneVNode, isVNode } from 'vue';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import { filterEmpty, initDefaultProps, getComponent } from '../_util/props-util'; import { initDefaultProps, getComponent, getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
export const SpinSize = PropTypes.oneOf(['small', 'default', 'large']); export const SpinSize = PropTypes.oneOf(['small', 'default', 'large']);
@ -89,13 +89,7 @@ export default {
updateSpinning.cancel(); updateSpinning.cancel();
} }
}, },
getChildren() { renderIndicator(prefixCls) {
if (this.$slots && this.$slots.default) {
return filterEmpty(this.$slots.default());
}
return null;
},
renderIndicator(h, prefixCls) {
const dotClassName = `${prefixCls}-dot`; const dotClassName = `${prefixCls}-dot`;
let indicator = getComponent(this, 'indicator'); let indicator = getComponent(this, 'indicator');
// should not be render default indicator when indicator value is null // should not be render default indicator when indicator value is null
@ -103,15 +97,14 @@ export default {
return null; return null;
} }
if (Array.isArray(indicator)) { if (Array.isArray(indicator)) {
indicator = filterEmpty(indicator);
indicator = indicator.length === 1 ? indicator[0] : indicator; indicator = indicator.length === 1 ? indicator[0] : indicator;
} }
if (isVNode(indicator)) { if (isVNode(indicator)) {
return cloneVNode(indicator, { class: dotClassName }); return cloneVNode(indicator, { class: dotClassName });
} }
if (defaultIndicator && isVNode(defaultIndicator(h))) { if (defaultIndicator && isVNode(defaultIndicator())) {
return cloneVNode(defaultIndicator(h), { class: dotClassName }); return cloneVNode(defaultIndicator(), { class: dotClassName });
} }
return ( return (
@ -124,7 +117,7 @@ export default {
); );
}, },
}, },
render(h) { render() {
const { size, prefixCls: customizePrefixCls, tip, wrapperClassName } = this.$props; const { size, prefixCls: customizePrefixCls, tip, wrapperClassName } = this.$props;
const { class: cls, style, ...divProps } = this.$attrs; const { class: cls, style, ...divProps } = this.$attrs;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
@ -137,17 +130,17 @@ export default {
[`${prefixCls}-lg`]: size === 'large', [`${prefixCls}-lg`]: size === 'large',
[`${prefixCls}-spinning`]: sSpinning, [`${prefixCls}-spinning`]: sSpinning,
[`${prefixCls}-show-text`]: !!tip, [`${prefixCls}-show-text`]: !!tip,
[cls]: true, [cls]: !!cls,
}; };
const spinElement = ( const spinElement = (
<div {...divProps} style={style} class={spinClassName}> <div {...divProps} style={style} class={spinClassName}>
{this.renderIndicator(h, prefixCls)} {this.renderIndicator(prefixCls)}
{tip ? <div class={`${prefixCls}-text`}>{tip}</div> : null} {tip ? <div class={`${prefixCls}-text`}>{tip}</div> : null}
</div> </div>
); );
const children = this.getChildren(); const children = getSlot(this);
if (children) { if (children && children.length) {
const containerClassName = { const containerClassName = {
[`${prefixCls}-container`]: true, [`${prefixCls}-container`]: true,
[`${prefixCls}-blur`]: sSpinning, [`${prefixCls}-blur`]: sSpinning,

View File

@ -1,9 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Spin should only affect the spin element when set style to a nested <Spin>xx</Spin> 1`] = ` exports[`Spin should only affect the spin element when set style to a nested <Spin>xx</Spin> 1`] = `
<div class="ant-spin-nested-loading" style="background: red;"> <div class="ant-spin-nested-loading">
<div> <div>
<div class="ant-spin ant-spin-spinning"><span class="ant-spin-dot ant-spin-dot-spin"><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i></span></div> <div style="background: red;" class="ant-spin ant-spin-spinning"><span class="ant-spin-dot ant-spin-dot-spin"><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i></span>
<!---->
</div>
</div> </div>
<div class="ant-spin-container ant-spin-blur"> <div class="ant-spin-container ant-spin-blur">
<div>content</div> <div>content</div>
@ -14,5 +16,6 @@ exports[`Spin should only affect the spin element when set style to a nested <Sp
exports[`Spin should render custom indicator when it's set 1`] = ` exports[`Spin should render custom indicator when it's set 1`] = `
<div class="ant-spin ant-spin-spinning"> <div class="ant-spin ant-spin-spinning">
<div class="custom-indicator ant-spin-dot"></div> <div class="custom-indicator ant-spin-dot"></div>
<!---->
</div> </div>
`; `;

View File

@ -34,8 +34,7 @@ describe('delay spinning', () => {
expect( expect(
wrapper wrapper
.findAll('.ant-spin') .findAll('.ant-spin')[0]
.at(0)
.classes() .classes()
.includes('ant-spin-spinning'), .includes('ant-spin-spinning'),
).toEqual(false); ).toEqual(false);
@ -46,8 +45,7 @@ describe('delay spinning', () => {
expect( expect(
wrapper wrapper
.findAll('.ant-spin') .findAll('.ant-spin')[0]
.at(0)
.classes() .classes()
.includes('ant-spin-spinning'), .includes('ant-spin-spinning'),
).toEqual(true); ).toEqual(true);

View File

@ -22,11 +22,7 @@ describe('Spin', () => {
// const customIndicator = <div className='custom-indicator' /> // const customIndicator = <div className='custom-indicator' />
const wrapper = mount({ const wrapper = mount({
render() { render() {
return ( return <Spin indicator={<div class="custom-indicator" />}></Spin>;
<Spin>
<div slot="indicator" class="custom-indicator" />
</Spin>
);
}, },
}); });
expect(wrapper.html()).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();

View File

@ -4,7 +4,7 @@
</div> </div>
</template> </template>
<script> <script>
import demo from '../antdv-demo/docs/skeleton/demo/index'; import demo from '../antdv-demo/docs/spin/demo/index';
export default { export default {
components: { components: {