From 4956ca9b92f17b55a0aa54b039b15abe834556be Mon Sep 17 00:00:00 2001 From: Nick Sellen Date: Sat, 21 Dec 2024 11:50:03 +0000 Subject: [PATCH] fix(task-item): fix read only checked handling Fixes #3676 --- packages/extension-task-item/src/task-item.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/extension-task-item/src/task-item.ts b/packages/extension-task-item/src/task-item.ts index cbb0a3f419..fa11a9216f 100644 --- a/packages/extension-task-item/src/task-item.ts +++ b/packages/extension-task-item/src/task-item.ts @@ -149,7 +149,7 @@ export const TaskItem = Node.create({ const { checked } = event.target as any - if (editor.isEditable && typeof getPos === 'function') { + if (typeof getPos === 'function') { editor .chain() .focus(undefined, { scrollIntoView: false }) @@ -161,6 +161,14 @@ export const TaskItem = Node.create({ } 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, @@ -170,12 +178,6 @@ export const TaskItem = Node.create({ }) .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]) => {