Skip to content

Commit

Permalink
fix(esl-utils): fix isRelativeNode signature (can accept undefined as…
Browse files Browse the repository at this point in the history
… a node)
  • Loading branch information
dshovchko committed May 29, 2024
1 parent fbaeec5 commit 4e2c7af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules/esl-popup/core/esl-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class ESLPopup extends ESLToggleable {
protected _onRefresh({target}: Event): void {
if (!isElement(target)) return;
const {activator, $container} = this;
if ($container === target || this.contains(target) || isRelativeNode(activator ?? null, target)) this._updatePosition();
if ($container === target || this.contains(target) || isRelativeNode(activator, target)) this._updatePosition();
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/modules/esl-utils/dom/traversing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ export const isMatches = (el: Element, matcher?: string | ((el: Element) => bool
};

/** Checks that `nodeA` and `nodeB` are from the same tree path */
export const isRelativeNode = (nodeA: Node | null, nodeB: Node | null): boolean => {
export function isRelativeNode(nodeA: null | undefined, nodeB: Node | null | undefined): false;
/** Checks that `nodeA` and `nodeB` are from the same tree path */
export function isRelativeNode(nodeA: Node | null | undefined, nodeB: null | undefined): false;
/** Checks that `nodeA` and `nodeB` are from the same tree path */
export function isRelativeNode(nodeA: Node | null | undefined, nodeB: Node | null | undefined): boolean;
export function isRelativeNode(nodeA: Node | null | undefined, nodeB: Node | null | undefined): boolean {
return !!(nodeA && nodeB) && (nodeA.contains(nodeB) || nodeB.contains(nodeA));
};
}

type IteratorFn = (el: Element) => Element | null;

Expand Down

0 comments on commit 4e2c7af

Please sign in to comment.