Skip to content

Commit

Permalink
feat(anchor-positioning-composable): add attachment resizing observer (
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriiiii authored Jun 19, 2024
1 parent 059d619 commit ad95018
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ export function usePositioning(anchor: Ref<HTMLElement>, attachment: Ref<HTMLEle
computePosition(attachInfo);

throttledComputePosition = utils.function.throttle(computePosition.bind(null, attachInfo), 30);
resizeObserver = new ResizeObserver(throttledComputePosition);
resizeObserver.observe(anchor.value);

const hasResizeObserver = window && window.ResizeObserver !== undefined;
if (hasResizeObserver) {
resizeObserver = new ResizeObserver(throttledComputePosition);
resizeObserver.observe(anchor.value);
resizeObserver.observe(attachment.value);
}

document.addEventListener('scroll', throttledComputePosition, true);
window.addEventListener('resize', throttledComputePosition, true);
} catch (error: any) {
Expand Down

0 comments on commit ad95018

Please sign in to comment.