Fix click effect in Popconfirm button

This commit is contained in:
afc163 2016-03-03 21:33:02 +08:00
parent 7518e30c3f
commit f7fb5b29f9

View File

@ -24,13 +24,19 @@ function insertSpace(child) {
return child; return child;
} }
function clearButton(button) {
button.className = button.className.replace(`${prefix}clicked`, '');
}
export default class Button extends React.Component { export default class Button extends React.Component {
handleClick(...args) { handleClick(...args) {
// Add click effect
const buttonNode = findDOMNode(this); const buttonNode = findDOMNode(this);
buttonNode.className = buttonNode.className.replace(`${prefix}clicked`, ''); clearButton(buttonNode);
setTimeout(() => { setTimeout(() => buttonNode.className += ` ${prefix}clicked`, 10);
buttonNode.className += ` ${prefix}clicked`; clearTimeout(this.timeout);
}, 10); this.timeout = setTimeout(() => clearButton(buttonNode), 500);
this.props.onClick(...args); this.props.onClick(...args);
} }
render() { render() {
@ -50,13 +56,16 @@ export default class Button extends React.Component {
[prefix + shape]: shape, [prefix + shape]: shape,
[prefix + sizeCls]: sizeCls, [prefix + sizeCls]: sizeCls,
[`${prefix}loading`]: ('loading' in props && props.loading !== false), [`${prefix}loading`]: ('loading' in props && props.loading !== false),
[className]: className [className]: className,
}); });
const kids = React.Children.map(children, insertSpace); const kids = React.Children.map(children, insertSpace);
return ( return (
<button {...others} type={htmlType || 'button'} className={classes} onClick={this.handleClick.bind(this)}> <button {...others}
type={htmlType || 'button'}
className={classes}
onClick={this.handleClick.bind(this)}>
{kids} {kids}
</button> </button>
); );