Fix #902
parent
e40c77442e
commit
9cd7fba6b5
|
@ -33,13 +33,15 @@ const factory = (Overlay, Button) => {
|
|||
type: PropTypes.oneOf([ 'accept', 'cancel', 'warning' ])
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
if (this.props.active && this.props.timeout) {
|
||||
this.scheduleTimeout(this.props);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (nextProps.active && nextProps.timeout) {
|
||||
if (this.curTimeout) clearTimeout(this.curTimeout);
|
||||
this.curTimeout = setTimeout(() => {
|
||||
nextProps.onTimeout();
|
||||
this.curTimeout = null;
|
||||
}, nextProps.timeout);
|
||||
this.scheduleTimeout(nextProps);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +49,15 @@ const factory = (Overlay, Button) => {
|
|||
clearTimeout(this.curTimeout);
|
||||
}
|
||||
|
||||
scheduleTimeout = props => {
|
||||
const { onTimeout, timeout } = props;
|
||||
if (this.curTimeout) clearTimeout(this.curTimeout);
|
||||
this.curTimeout = setTimeout(() => {
|
||||
if (onTimeout) onTimeout();
|
||||
this.curTimeout = null;
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
render () {
|
||||
const {action, active, children, label, onClick, theme, type } = this.props;
|
||||
const className = classnames([theme.snackbar, theme[type]], {
|
||||
|
|
Loading…
Reference in New Issue