Skip to content

Commit

Permalink
return boolean from getChecked if list type is check
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed May 12, 2024
1 parent a7839b7 commit 65eb5bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 7 additions & 1 deletion packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions packages/lexical-list/src/formatList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 65eb5bf

Please sign in to comment.