Skip to content

Commit

Permalink
[MOL-16700][AM] use client width instead of inner width to cater for …
Browse files Browse the repository at this point in the history
…scrollbar
  • Loading branch information
Anu Mutyala committed Nov 20, 2024
1 parent 5a1803f commit 06aaad6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/local-nav/local-nav-dropdown/local-nav-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ const Component = (
// =============================================================================
const detectStickyRef = useRef<HTMLSpanElement>(null);
const dropdownRef = useRef<HTMLDivElement>(null);
const navWrapperRef = useRef<HTMLElement>(null);
const [isStickied, setIsStickied] = useState<boolean>(false);
const [isDropdownExpanded, setIsDropdownExpanded] =
useState<boolean>(false);
const [viewportHeight, setViewportHeight] = useState(0);
const [dropdowntHeight, setDropdownHeight] = useState(0);
const [dynamicMargin, setDynamicMargin] = useState(0);
const navWrapperRef = useRef<HTMLElement>(null);
useImperativeHandle(ref, () => navWrapperRef.current);
const navTestId = testId || "local-nav-dropdown";

useImperativeHandle(ref, () => navWrapperRef.current);

const labelText =
selectedItemIndex >= 0 && isStickied
? items[selectedItemIndex].title
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 06aaad6

Please sign in to comment.