Skip to content

Commit 8bc9f54

Browse files
committed
Copy to clipboard fix
1 parent 42e29d6 commit 8bc9f54

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

website/src/js/playground.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function init() {
186186

187187
return isPlain
188188
? `{ ${ props.join(', ') } }`
189-
: `${ value.constructor?.name || 'Object' } { ${ props.join(', ') } }`;
189+
: `${ value.constructor?.name ?? 'Object' } { ${ props.join(', ') } }`;
190190
}
191191

192192
return String(value);
@@ -210,22 +210,19 @@ function init() {
210210

211211
const textArea = document.createElement('textarea');
212212
textArea.value = text;
213-
textArea.style.position = 'fixed';
214-
textArea.style.top = '0';
215-
textArea.style.left = '0';
216-
textArea.style.opacity = '0';
213+
textArea.classList.add('copy-fallback');
217214
document.body.appendChild(textArea);
218215
textArea.focus();
219216
textArea.select();
220217

221218
try {
222219
const successful = document.execCommand('copy');
223220
document.body.removeChild(textArea);
224-
if (successful) return Promise.resolve();
225-
return Promise.reject(new Error('Copy command was unsuccessful'));
221+
if (successful) return true;
222+
throw new Error('Copy command was unsuccessful');
226223
} catch (err) {
227224
document.body.removeChild(textArea);
228-
return Promise.reject(err);
225+
throw err;
229226
}
230227
}
231228

website/src/scss/parts/playground.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,10 @@
220220
}
221221
}
222222
}
223+
224+
.copy-fallback {
225+
position: fixed;
226+
top: 0;
227+
left: 0;
228+
opacity: 0;
229+
}

0 commit comments

Comments
 (0)