Click to copy to work with entire div including icon
This commit is contained in:
parent
5f99629930
commit
57fab11316
2 changed files with 8 additions and 5 deletions
|
@ -2,8 +2,8 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
cursor: pointer;
|
||||||
.click-to-copy {
|
.click-to-copy {
|
||||||
cursor: pointer;
|
|
||||||
border: none;
|
border: none;
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
|
@ -6,9 +6,10 @@ class ClickToCopy extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
this.copyToClipboard = this.copyToClipboard.bind(this);
|
this.copyToClipboard = this.copyToClipboard.bind(this);
|
||||||
}
|
}
|
||||||
copyToClipboard (event) {
|
copyToClipboard () {
|
||||||
const elementToCopy = event.target.id;
|
const elementToCopy = this.props.id;
|
||||||
const element = document.getElementById(elementToCopy);
|
const element = document.getElementById(elementToCopy);
|
||||||
|
console.log(elementToCopy);
|
||||||
element.select();
|
element.select();
|
||||||
try {
|
try {
|
||||||
document.execCommand('copy');
|
document.execCommand('copy');
|
||||||
|
@ -19,11 +20,13 @@ class ClickToCopy extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const {id, value} = this.props;
|
const {id, value} = this.props;
|
||||||
return (
|
return (
|
||||||
<div className='click-to-copy-wrap'>
|
<div
|
||||||
|
className='click-to-copy-wrap'
|
||||||
|
onClick={this.copyToClipboard}
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
id={id}
|
id={id}
|
||||||
value={value}
|
value={value}
|
||||||
onClick={this.copyToClipboard}
|
|
||||||
type='text'
|
type='text'
|
||||||
className='click-to-copy'
|
className='click-to-copy'
|
||||||
readOnly
|
readOnly
|
||||||
|
|
Loading…
Add table
Reference in a new issue