Skip to content

Commit 9a0af5d

Browse files
GormanDesignbdbch
andauthoredMar 31, 2025··
fix(link): fixes links with marks (#6078)
* fixes links with marks * Create popular-geckos-pay.md * Update clickHandler.ts --------- Co-authored-by: bdbch <6538827+bdbch@users.noreply.github.com>
1 parent d88244d commit 9a0af5d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed
 

‎.changeset/popular-geckos-pay.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tiptap/extension-link": patch
3+
---
4+
5+
Fixed links with marks not registering click events correctly

‎packages/extension-link/src/helpers/clickHandler.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,28 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
1919
return false
2020
}
2121

22-
let a = event.target as HTMLElement
23-
const els = []
24-
25-
while (a.nodeName !== 'DIV') {
26-
els.push(a)
27-
a = a.parentNode as HTMLElement
22+
let link: HTMLAnchorElement | null = null
23+
24+
if (event.target instanceof HTMLAnchorElement) {
25+
link = event.target
26+
} else {
27+
let a = event.target as HTMLElement
28+
const els = []
29+
30+
while (a.nodeName !== 'DIV') {
31+
els.push(a)
32+
a = a.parentNode as HTMLElement
33+
}
34+
link = els.find(
35+
value => value.nodeName === 'A',
36+
) as HTMLAnchorElement
2837
}
2938

30-
if (!els.find(value => value.nodeName === 'A')) {
39+
if (!link) {
3140
return false
3241
}
3342

3443
const attrs = getAttributes(view.state, options.type.name)
35-
const link = (event.target as HTMLAnchorElement)
36-
3744
const href = link?.href ?? attrs.href
3845
const target = link?.target ?? attrs.target
3946

0 commit comments

Comments
 (0)
Please sign in to comment.