Fix spin delay issue if mounts with spinning=true (#10727)

* Fix spin delay issue if mounts with spinning=true

* Add test for spin delay issue

* Update spin lifecycle method
This commit is contained in:
bLue 2018-06-08 23:13:47 +08:00 committed by Wei Zhu
parent 5174801b95
commit 8e26b6823a
2 changed files with 15 additions and 0 deletions

View File

@ -20,4 +20,11 @@ describe('Spin', () => {
);
expect(wrapper).toMatchSnapshot();
});
it('should render with delay when it\'s mounted with spinning=true and delay', () => {
const wrapper = shallow(
<Spin spinning delay={500} />
);
expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false);
});
});

View File

@ -56,6 +56,14 @@ export default class Spin extends React.Component<SpinProps, SpinState> {
return !!(this.props && this.props.children);
}
componentDidMount() {
const { spinning, delay } = this.props;
if (spinning && delay && !isNaN(Number(delay))) {
this.setState({ spinning: false });
this.delayTimeout = window.setTimeout(() => this.setState({ spinning }), delay);
}
}
componentWillUnmount() {
if (this.debounceTimeout) {
clearTimeout(this.debounceTimeout);