Skip to content

Commit

Permalink
Accept undefined in clientRect/outOfBounds hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Nov 19, 2023
1 parent 2f767fd commit 489a1c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const cleanupHookInstance = (element: HTMLElement, setRenderTime: SetRenderTime)
refs.maybeCleanupElement();
};

const useBoundingClientRect = (element: HTMLElement | null): Rect | EmptyRect => {
const useBoundingClientRect = (element?: HTMLElement | null): Rect | EmptyRect => {
// Flip the bit to trigger a new return value from this hook
const [, setRenderTime] = useState<number>(0);

Expand Down
4 changes: 2 additions & 2 deletions packages/use-is-out-of-bounds/src/useIsOutOfBounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const INITIAL_OUT_OF_BOUNDS_HAS_LAYOUT: OutOfBounds = Object.freeze({
hasLayout: true,
});

const getOverflowHiddenParent = (element: MaybeHTMLElement): MaybeHTMLElement => {
const getOverflowHiddenParent = (element?: MaybeHTMLElement): MaybeHTMLElement => {
while (element?.parentElement) {
// If we’ve reached the body, use that as offsetParent
if (element.parentElement.tagName === 'BODY') return element.parentElement;
Expand Down Expand Up @@ -76,7 +76,7 @@ const getIsCurrentDirectionBefore = ({
return positionAfter < length / 2;
};

const useIsOutOfBounds = (element: MaybeHTMLElement): OutOfBounds => {
const useIsOutOfBounds = (element?: MaybeHTMLElement): OutOfBounds => {
const outOfBoundsRef = useRef<OutOfBounds>(INITIAL_OUT_OF_BOUNDS);
const computedStyleRef = useRef<CSSStyleDeclaration | null>(null);
const elementRect = useBoundingClientRect(element);
Expand Down

0 comments on commit 489a1c0

Please sign in to comment.