diff --git a/packages/react-components/react-aria/library/src/activedescendant/scrollIntoView.ts b/packages/react-components/react-aria/library/src/activedescendant/scrollIntoView.ts index e6a5ae1b6f22e4..6d9f83b10d4deb 100644 --- a/packages/react-components/react-aria/library/src/activedescendant/scrollIntoView.ts +++ b/packages/react-components/react-aria/library/src/activedescendant/scrollIntoView.ts @@ -49,6 +49,14 @@ const getTotalOffsetTop = (element: HTMLElement, scrollParent: HTMLElement): num return scrollParent.offsetTop * -1; } + // Handle position: fixed elements where offsetTop is unreliable + const win = element.ownerDocument?.defaultView; + const isFixed = win && win.getComputedStyle(element).position === 'fixed'; + + if (isFixed) { + return element.getBoundingClientRect().top + getTotalOffsetTop(element.offsetParent as HTMLElement, scrollParent); + } + return element.offsetTop + getTotalOffsetTop(element.offsetParent as HTMLElement, scrollParent); };