Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize getParentElement internally when traversing up the DOM tree #3576

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/lexical/src/LexicalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function getNearestEditorFromDOMNode(
if (editor != null) {
return editor;
}
currentNode = currentNode.parentNode;
currentNode = getParentElement(currentNode);
}
return null;
}
Expand Down Expand Up @@ -404,7 +404,7 @@ export function $getNearestNodeFromDOMNode(
if (node !== null) {
return node;
}
dom = dom.parentNode;
dom = getParentElement(dom);
}
return null;
}
Expand Down Expand Up @@ -513,7 +513,7 @@ function getNodeKeyFromDOM(
if (key !== undefined) {
return key;
}
node = node.parentNode;
node = getParentElement(node);
}
return null;
}
Expand Down Expand Up @@ -1141,9 +1141,9 @@ export function getElementByKeyOrThrow(
return element;
}

export function getParentElement(element: HTMLElement): HTMLElement | null {
export function getParentElement(node: Node): HTMLElement | null {
const parentElement =
(element as HTMLSlotElement).assignedSlot || element.parentElement;
(node as HTMLSlotElement).assignedSlot || node.parentElement;
return parentElement !== null && parentElement.nodeType === 11
? ((parentElement as unknown as ShadowRoot).host as HTMLElement)
: parentElement;
Expand Down