From 65eb5bfe627bebd9cd955fc6ec7edadb24c4ab08 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sun, 12 May 2024 22:53:32 +0530 Subject: [PATCH] return boolean from getChecked if list type is check --- packages/lexical-list/src/LexicalListItemNode.ts | 8 +++++++- packages/lexical-list/src/formatList.ts | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/lexical-list/src/LexicalListItemNode.ts b/packages/lexical-list/src/LexicalListItemNode.ts index 497583adf88..ca9b8013508 100644 --- a/packages/lexical-list/src/LexicalListItemNode.ts +++ b/packages/lexical-list/src/LexicalListItemNode.ts @@ -321,7 +321,13 @@ export class ListItemNode extends ElementNode { getChecked(): boolean | undefined { const self = this.getLatest(); - return self.__checked; + const parent = this.getParent(); + if (!$isListNode(parent)) { + invariant(false, 'getChecked: list node is not parent of list item node'); + } + const listType = parent.getListType(); + + return listType === 'check' ? Boolean(self.__checked) : undefined; } setChecked(checked?: boolean): void { diff --git a/packages/lexical-list/src/formatList.ts b/packages/lexical-list/src/formatList.ts index ff9c098c267..2263edfb757 100644 --- a/packages/lexical-list/src/formatList.ts +++ b/packages/lexical-list/src/formatList.ts @@ -83,9 +83,7 @@ export function insertList(editor: LexicalEditor, listType: ListType): void { if ($isRootOrShadowRoot(anchorNodeParent)) { anchorNode.replace(list); - const listItem = $createListItemNode( - listType === 'check' ? false : undefined, - ); + const listItem = $createListItemNode(); if ($isElementNode(anchorNode)) { listItem.setFormat(anchorNode.getFormatType()); listItem.setIndent(anchorNode.getIndent()); @@ -158,9 +156,7 @@ function createListOrMerge(node: ElementNode, listType: ListType): ListNode { const previousSibling = node.getPreviousSibling(); const nextSibling = node.getNextSibling(); - const listItem = $createListItemNode( - listType === 'check' ? false : undefined, - ); + const listItem = $createListItemNode(); listItem.setFormat(node.getFormatType()); listItem.setIndent(node.getIndent()); append(listItem, node.getChildren());