chore: fix issue with focus getting lost after pressing up/down after clicking inside checklist [skip e2e]

This commit is contained in:
Aman Harwara
2024-07-17 15:06:41 +05:30
parent 5a7641c27f
commit 6e75d29664

View File

@@ -1,4 +1,4 @@
import { $isListItemNode, $isListNode, INSERT_CHECK_LIST_COMMAND, insertList, ListNode } from '@lexical/list' import { $isListItemNode, INSERT_CHECK_LIST_COMMAND, insertList, ListNode } from '@lexical/list'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { calculateZoomLevel, isHTMLElement, mergeRegister } from '@lexical/utils' import { calculateZoomLevel, isHTMLElement, mergeRegister } from '@lexical/utils'
import { import {
@@ -47,12 +47,11 @@ export function CheckListPlugin(): null {
return return
} }
editor.update(() => { editor.getRootElement()?.focus()
const targetNode = $getNearestNodeFromDOMNode(target)
const parentNode = targetNode?.getParent() const parentNode = target.parentNode
// @ts-expect-error internal field
if (!$isListNode(parentNode) || parentNode.getListType() !== 'check') { if (!parentNode || parentNode.__lexicalListType !== 'check') {
return return
} }
@@ -78,7 +77,6 @@ export function CheckListPlugin(): null {
if (isWithinHorizontalThreshold && isWithinVerticalThreshold) { if (isWithinHorizontalThreshold && isWithinVerticalThreshold) {
callback() callback()
} }
})
} }
function handleClick(event: Event) { function handleClick(event: Event) {
@@ -100,7 +98,6 @@ export function CheckListPlugin(): null {
return return
} }
domNode.focus()
node.toggleChecked() node.toggleChecked()
}) })
}) })