Skip to content

Commit

Permalink
feat(esl-utils): create utility to get element that is viewport for s…
Browse files Browse the repository at this point in the history
…pecified element
  • Loading branch information
dshovchko committed Aug 8, 2024
1 parent 0bd7a77 commit 63d869b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/esl-utils/dom/scroll/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ export function isScrollable(element: Element): boolean {
const {overflow, overflowX, overflowY} = getComputedStyle(element);
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
}

/**
* Get the element that is the viewport for the specified element.
* @param node - element for which to get the viewport
*/
export function getViewportForEl(node: Element): Element | null {
return getListScrollParents(node).filter((el) => el.scrollHeight !== el.clientHeight).shift()!;
}

0 comments on commit 63d869b

Please # to comment.