Skip to content

Commit

Permalink
Created getHiddenParent helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiglesias93 committed Nov 27, 2021
1 parent 74d45e9 commit 89c0e36
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions helpers/getHiddenParent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { isVisible } from '.';

/**
* @returns The first hidden parent element, or the element itself (if hidden).
* If the element is already visible, the function returns `undefined`.
*
* @param element The reference element.
*/
export const getHiddenParent = (element: HTMLElement): HTMLElement | undefined => {
if (isVisible(element)) return;

let previousElement = element;

const checkParent = ({ parentElement }: HTMLElement) => {
if (!parentElement) return;

if (isVisible(parentElement)) return;

previousElement = parentElement;
checkParent(parentElement);
};

checkParent(element);

return previousElement;
};
1 change: 1 addition & 0 deletions helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { findTextNode } from './findTextNode';
export { getAllParents } from './getAllParents';
export { getDistanceFromTop } from './getDistanceFromTop';
export { getFormFieldValue } from './getFormFieldValue';
export { getHiddenParent } from './getHiddenParent';
export { getObjectEntries } from './getObjectEntries';
export { getObjectKeys } from './getObjectKeys';
export { isScrollable } from './isScrollable';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finsweet/ts-utils",
"version": "0.26.0",
"version": "0.27.0",
"description": "Typescript utils for custom Webflow projects.",
"main": "index.ts",
"module": "index.ts",
Expand Down

0 comments on commit 89c0e36

Please sign in to comment.