Skip to content

Commit bec3f67

Browse files
committed
🐛 Fix Svelte Copy component returning undefined when copying text
1 parent 1e95bd9 commit bec3f67

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/Copy/Copy.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
let copiedButton: HTMLSpanElement
2626
2727
const copyText = () => {
28-
const text = copyButton.parentElement?.previousSibling?.textContent?.trim()
29-
|| (copyButton.parentElement?.previousSibling as Text)?.wholeText?.trim()
30-
|| copyButton.parentElement?.previousElementSibling?.textContent?.trim()
28+
const text = copyButton
29+
.parentElement
30+
?.parentElement
31+
?.querySelector('[data-id="text"]')
32+
?.textContent?.trim()
3133
3234
copyButton.style.opacity = '0'
3335
copyButton.style.pointerEvents = 'none'
@@ -45,7 +47,7 @@
4547
data-tooltip={tooltip || undefined}
4648
data-position={tooltipPosition}
4749
>
48-
<slot />
50+
<span data-id="text"><slot /></span>
4951
<div class={styles.icons}>
5052
<button
5153
class={styles['copy-icon']}

0 commit comments

Comments
 (0)