Skip to content

Commit

Permalink
fix(task-item): fix read only checked handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksellen committed Dec 21, 2024
1 parent d735cf3 commit 4956ca9
Showing 1 changed file with 9 additions and 7 deletions.
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 (!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

0 comments on commit 4956ca9

Please sign in to comment.