diff --git a/src/local-nav/local-nav-dropdown/local-nav-dropdown.tsx b/src/local-nav/local-nav-dropdown/local-nav-dropdown.tsx index 76dfdcc53..50a17fad5 100644 --- a/src/local-nav/local-nav-dropdown/local-nav-dropdown.tsx +++ b/src/local-nav/local-nav-dropdown/local-nav-dropdown.tsx @@ -32,16 +32,17 @@ const Component = ( // ============================================================================= const detectStickyRef = useRef(null); const dropdownRef = useRef(null); + const navWrapperRef = useRef(null); const [isStickied, setIsStickied] = useState(false); const [isDropdownExpanded, setIsDropdownExpanded] = useState(false); const [viewportHeight, setViewportHeight] = useState(0); const [dropdowntHeight, setDropdownHeight] = useState(0); const [dynamicMargin, setDynamicMargin] = useState(0); - const navWrapperRef = useRef(null); - useImperativeHandle(ref, () => navWrapperRef.current); const navTestId = testId || "local-nav-dropdown"; + useImperativeHandle(ref, () => navWrapperRef.current); + const labelText = selectedItemIndex >= 0 && isStickied ? items[selectedItemIndex].title @@ -96,7 +97,8 @@ const Component = ( const dropdown = navWrapperRef?.current; if (dropdown) { const dropdownRect = dropdown.getBoundingClientRect(); - const spaceToRight = window.innerWidth - dropdownRect.right; + const spaceToRight = + document.body.clientWidth - dropdownRect.right; const spaceToLeft = dropdownRect.left; // Calculate the padding needed to balance the dropdown in the viewport const sidePadding = Math.max(spaceToRight, spaceToLeft);