Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(task-item): fix read only checked handling #5952

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions packages/extension-task-item/src/task-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const TaskItem = Node.create<TaskItemOptions>({

const { checked } = event.target as any

if (editor.isEditable && typeof getPos === 'function') {
if (typeof getPos === 'function') {
editor
.chain()
.focus(undefined, { scrollIntoView: false })
Expand All @@ -161,6 +161,14 @@ export const TaskItem = Node.create<TaskItemOptions>({
}
const currentNode = tr.doc.nodeAt(position)

if (!editor.isEditable && this.options.onReadOnlyChecked) {
// Reset state if onReadOnlyChecked returns false
if (!currentNode || !this.options.onReadOnlyChecked(currentNode, checked)) {
checkbox.checked = !checkbox.checked
return false
}
}

tr.setNodeMarkup(position, undefined, {
...currentNode?.attrs,
checked,
Expand All @@ -170,12 +178,6 @@ export const TaskItem = Node.create<TaskItemOptions>({
})
.run()
}
if (!editor.isEditable && this.options.onReadOnlyChecked) {
// Reset state if onReadOnlyChecked returns false
if (!this.options.onReadOnlyChecked(node, checked)) {
checkbox.checked = !checkbox.checked
}
}
})

Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
Expand Down