Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(link): fixes links with marks #6078

Merged
merged 4 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-geckos-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-link": patch
---

Fixed links with marks not registering click events correctly
25 changes: 16 additions & 9 deletions packages/extension-link/src/helpers/clickHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
return false
}

let a = event.target as HTMLElement
const els = []

while (a.nodeName !== 'DIV') {
els.push(a)
a = a.parentNode as HTMLElement
let link: HTMLAnchorElement | null = null

if (event.target instanceof HTMLAnchorElement) {
link = event.target
} else {
let a = event.target as HTMLElement
const els = []

while (a.nodeName !== 'DIV') {
els.push(a)
a = a.parentNode as HTMLElement
}
link = els.find(
value => value.nodeName === 'A',
) as HTMLAnchorElement
}

if (!els.find(value => value.nodeName === 'A')) {
if (!link) {
return false
}

const attrs = getAttributes(view.state, options.type.name)
const link = (event.target as HTMLAnchorElement)

const href = link?.href ?? attrs.href
const target = link?.target ?? attrs.target

Expand Down