Skip to content

Commit 6f4944e

Browse files
authored
feat(headings): Copy link to clipboard on click (#11300)
1 parent 3daab70 commit 6f4944e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/smartLink.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'use client';
2+
3+
import {useCallback} from 'react';
14
import Link from 'next/link';
25

36
import {ExternalLink} from './externalLink';
@@ -27,6 +30,13 @@ export function SmartLink({
2730
}: Props) {
2831
const realTo = to || href || '';
2932

33+
const handleAutolinkClick = useCallback((e: React.MouseEvent) => {
34+
const link = e.currentTarget as HTMLAnchorElement;
35+
if (link.classList.contains('autolink-heading')) {
36+
navigator.clipboard.writeText(link.href);
37+
}
38+
}, []);
39+
3040
if (remote || realTo?.indexOf('://') !== -1) {
3141
return (
3242
<ExternalLink href={realTo} className={className} {...props}>
@@ -38,6 +48,7 @@ export function SmartLink({
3848
return (
3949
<Link
4050
href={to || href || ''}
51+
onClick={handleAutolinkClick}
4152
className={`${isActive ? activeClassName : ''} ${className}`}
4253
{...props}
4354
>

0 commit comments

Comments
 (0)