From f834a048a0e6db2159c82796eabd36cecec99b97 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sun, 4 Aug 2024 08:57:46 +0530 Subject: [PATCH] When creating a new check list, set the `checked` value of the list item to `false` instead of `undefined` (#5978) --- packages/lexical-list/src/LexicalListItemNode.ts | 11 +++++++++-- packages/lexical-list/src/formatList.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/lexical-list/src/LexicalListItemNode.ts b/packages/lexical-list/src/LexicalListItemNode.ts index 72b9ac1b612..d2091e2c10a 100644 --- a/packages/lexical-list/src/LexicalListItemNode.ts +++ b/packages/lexical-list/src/LexicalListItemNode.ts @@ -6,7 +6,7 @@ * */ -import type {ListNode} from './'; +import type {ListNode, ListType} from './'; import type { BaseSelection, DOMConversionMap, @@ -320,7 +320,14 @@ export class ListItemNode extends ElementNode { getChecked(): boolean | undefined { const self = this.getLatest(); - return self.__checked; + let listType: ListType | undefined; + + const parent = this.getParent(); + if ($isListNode(parent)) { + 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 565887c57d5..6d4a5cb41b5 100644 --- a/packages/lexical-list/src/formatList.ts +++ b/packages/lexical-list/src/formatList.ts @@ -297,7 +297,7 @@ export function updateChildrenListItemValue(list: ListNode): void { if (child.getValue() !== value) { child.setValue(value); } - if (isNotChecklist && child.getChecked() != null) { + if (isNotChecklist && child.getLatest().__checked != null) { child.setChecked(undefined); } if (!$isListNode(child.getFirstChild())) {