Fix useHasWrapped hook

This commit is contained in:
Fedor Indutny 2024-11-06 22:43:27 -08:00 committed by GitHub
parent ac09a508f1
commit 2bf34fbf1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,10 @@ import type { Ref } from 'react';
import { useEffect, useState } from 'react';
import { first, last, noop } from 'lodash';
function getBottom(element: Readonly<Element>): number {
return element.getBoundingClientRect().bottom;
}
function getTop(element: Readonly<Element>): number {
return element.getBoundingClientRect().top;
}
@ -22,7 +26,7 @@ function isWrapped(element: Readonly<null | HTMLElement>): boolean {
firstChild &&
lastChild &&
firstChild !== lastChild &&
getTop(firstChild) !== getTop(lastChild)
getBottom(firstChild) <= getTop(lastChild)
);
}