Stop onClick propagation after click (#4700)

This commit is contained in:
Jaco Greeff 2017-02-28 14:20:43 +01:00 committed by GitHub
parent 1b8a47fa4a
commit ab98ec3bf7

View File

@ -16,6 +16,7 @@
import { IconButton } from 'material-ui'; import { IconButton } from 'material-ui';
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import Clipboard from 'react-copy-to-clipboard'; import Clipboard from 'react-copy-to-clipboard';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
@ -64,14 +65,33 @@ class CopyToClipboard extends Component {
const { copied } = this.state; const { copied } = this.state;
return ( return (
<Clipboard onCopy={ this.onCopy } text={ data }> <Clipboard
<div className={ styles.wrapper }> onCopy={ this.onCopy }
text={ data }
>
<div
className={ styles.wrapper }
onClick={ this.onClick }
>
<IconButton <IconButton
disableTouchRipple disableTouchRipple
style={ { width: size, height: size, padding: '0' } } iconStyle={ {
iconStyle={ { width: size, height: size } } height: size,
width: size
} }
style={ {
height: size,
padding: '0',
width: size
} }
> >
<CopyIcon color={ copied ? disabledTextColor : textColor } /> <CopyIcon
color={
copied
? disabledTextColor
: textColor
}
/>
</IconButton> </IconButton>
</div> </div>
</Clipboard> </Clipboard>
@ -82,9 +102,13 @@ class CopyToClipboard extends Component {
const { data, onCopy, cooldown, showSnackbar } = this.props; const { data, onCopy, cooldown, showSnackbar } = this.props;
const message = ( const message = (
<div className={ styles.container }> <div className={ styles.container }>
<span>copied </span> <FormattedMessage
<code className={ styles.data }> { data } </code> id='ui.copyToClipboard.copied'
<span> to clipboard</span> defaultMessage='copied {data} to clipboard'
values={ {
data: <code className={ styles.data }> { data } </code>
} }
/>
</div> </div>
); );
@ -98,6 +122,11 @@ class CopyToClipboard extends Component {
showSnackbar(message, cooldown); showSnackbar(message, cooldown);
onCopy(); onCopy();
} }
onClick = (event) => {
event.stopPropagation();
event.preventDefault();
}
} }
function mapDispatchToProps (dispatch) { function mapDispatchToProps (dispatch) {