From 8874e5e5e622892ed18d576b6e24ee6f8c2c8f1c Mon Sep 17 00:00:00 2001 From: Kasper Nilsson Date: Wed, 2 Feb 2022 14:56:05 -0800 Subject: [PATCH] Add option to allow task items to be checkable (uncontrolled) Useful for drafting interactive documents. Could see this expanding to potentially also support passing a callback? Will happily update documentation if this approach is accepted! --- packages/extension-task-item/src/task-item.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/extension-task-item/src/task-item.ts b/packages/extension-task-item/src/task-item.ts index c7f02883..c0e644ba 100644 --- a/packages/extension-task-item/src/task-item.ts +++ b/packages/extension-task-item/src/task-item.ts @@ -2,6 +2,7 @@ import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core' export interface TaskItemOptions { nested: boolean, + checkable: boolean, HTMLAttributes: Record, } @@ -13,6 +14,7 @@ export const TaskItem = Node.create({ addOptions() { return { nested: false, + checkable: false, HTMLAttributes: {}, } }, @@ -105,9 +107,9 @@ export const TaskItem = Node.create({ checkboxWrapper.contentEditable = 'false' checkbox.type = 'checkbox' checkbox.addEventListener('change', event => { - // if the editor isn’t editable + // if the editor isn’t editable and the item isn't checkable // we have to undo the latest change - if (!editor.isEditable) { + if (!editor.isEditable && !checkable) { checkbox.checked = !checkbox.checked return