Skip to content

Commit

Permalink
Fix DropdownMenu positioning issue (#2812)
Browse files Browse the repository at this point in the history
* fix(dropdown-menu): fix an issue with dropdown positioning

* chore: changeset added
  • Loading branch information
CarlosCortizasCT authored May 13, 2024
1 parent 0232120 commit f1fff9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .changeset/kind-countries-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@commercetools-uikit/dropdown-menu': patch
'@commercetools-uikit/data-table-manager': patch
---

We fixed an issue with the `DropdownMenu` component when using these values:

* `menuPosition`: right
* `menuHorizontalConstraint`: auto

In that situation, the width and positioning of the floating menu was not correctly calculated.
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ function DropdownBaseMenu(props: TDropdownBaseMenuProps) {
if (props.isOpen && props.triggerElementRef.current && menuRef.current) {
const triggerElementCoordinates =
props.triggerElementRef.current.getBoundingClientRect();
const menuElementCoordinates = menuRef.current.getBoundingClientRect();

menuRef.current.style.top = `${
triggerElementCoordinates.top + triggerElementCoordinates.height
}px`;
menuRef.current.style.left =
props.menuPosition === 'left'
? `${triggerElementCoordinates.left}px`
: `${
triggerElementCoordinates.left +
triggerElementCoordinates.width -
menuElementCoordinates.width
}px`;
if (props.menuPosition === 'left') {
menuRef.current.style.left = `${triggerElementCoordinates.left}px`;
menuRef.current.style.removeProperty('right');
} else {
menuRef.current.style.right = `${
window.innerWidth - triggerElementCoordinates.right
}px`;
menuRef.current.style.removeProperty('left');
}
menuRef.current.style.maxHeight = props.menuMaxHeight
? `${props.menuMaxHeight}px`
: `calc(${
Expand Down

0 comments on commit f1fff9f

Please sign in to comment.