Fix useHasWrapped hook

This commit is contained in:
automated-signal 2024-11-12 15:56:09 -06:00 committed by GitHub
parent 1fd0144579
commit ee5ba7c32d
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 { useEffect, useState } from 'react';
import { first, last, noop } from 'lodash'; import { first, last, noop } from 'lodash';
function getBottom(element: Readonly<Element>): number {
return element.getBoundingClientRect().bottom;
}
function getTop(element: Readonly<Element>): number { function getTop(element: Readonly<Element>): number {
return element.getBoundingClientRect().top; return element.getBoundingClientRect().top;
} }
@ -22,7 +26,7 @@ function isWrapped(element: Readonly<null | HTMLElement>): boolean {
firstChild && firstChild &&
lastChild && lastChild &&
firstChild !== lastChild && firstChild !== lastChild &&
getTop(firstChild) !== getTop(lastChild) getBottom(firstChild) <= getTop(lastChild)
); );
} }