mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
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:
parent
5174801b95
commit
8e26b6823a
@ -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);
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user