From c58a753e9442c1766050a1a4733e56d553d2e8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 27 May 2021 18:33:15 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20prevent=20checkbox=20change=20when=20edi?= =?UTF-8?q?tor=20isn=E2=80=99t=20editable,=20fix=20#1386?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/extension-task-item/src/task-item.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/extension-task-item/src/task-item.ts b/packages/extension-task-item/src/task-item.ts index a86216e7..5299b70f 100644 --- a/packages/extension-task-item/src/task-item.ts +++ b/packages/extension-task-item/src/task-item.ts @@ -86,9 +86,17 @@ export const TaskItem = Node.create({ checkboxWrapper.contentEditable = 'false' checkbox.type = 'checkbox' checkbox.addEventListener('change', event => { + // if the editor isn’t editable + // we have to undo the latest change + if (!editor.isEditable) { + checkbox.checked = !checkbox.checked + + return + } + const { checked } = event.target as any - if (typeof getPos === 'function') { + if (editor.isEditable && typeof getPos === 'function') { editor .chain() .focus()