Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dropdowns.next/src/elements/menu/MenuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const MenuList = forwardRef<HTMLUListElement, IMenuListProps>(
>
<StyledMenu
data-garden-animate-arrow={isVisible}
arrowPosition={hasArrow ? toArrowPosition(placement) : undefined}
arrowPosition={hasArrow ? toArrowPosition(theme.rtl, placement) : undefined}
isCompact={isCompact}
minHeight={minHeight}
maxHeight={maxHeight}
Expand Down
23 changes: 16 additions & 7 deletions packages/dropdowns.next/src/elements/menu/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,9 @@ export const toFloatingPlacement = (
left: 'right',
'left-start': 'right-start',
'left-end': 'right-end',
'top-start': 'top-end',
'top-end': 'top-start',
right: 'left',
'right-start': 'left-start',
'right-end': 'left-end',
'bottom-start': 'bottom-end',
'bottom-end': 'bottom-start'
'right-end': 'left-end'
};

retVal = placementMapRtl[retVal] || retVal;
Expand Down Expand Up @@ -138,11 +134,12 @@ export const toMenuPosition = (placement?: FloatingPlacement): MenuPosition => {
/**
* Convert Floating-UI placement to a valid `arrowStyles` position.
*
* @param isRtl Determines if layout is right-to-left.
* @param placement A Floating-UI placement.
*
* @returns An `arrowStyles` position.
*/
export const toArrowPosition = (placement?: FloatingPlacement): ArrowPosition => {
export const toArrowPosition = (isRtl: boolean, placement?: FloatingPlacement): ArrowPosition => {
const positionMap: Record<FloatingPlacement, ArrowPosition> = {
auto: 'top',
top: 'bottom',
Expand All @@ -158,8 +155,20 @@ export const toArrowPosition = (placement?: FloatingPlacement): ArrowPosition =>
'left-start': 'right-top',
'left-end': 'right-bottom'
};
let retVal = positionMap[placement || 'auto'];

if (isRtl) {
const rtlPositionMap: Record<string, ArrowPosition> = {
'bottom-left': 'bottom-right',
'bottom-right': 'bottom-left',
'top-left': 'top-right',
'top-right': 'top-left'
};

return positionMap[placement || 'auto'];
retVal = rtlPositionMap[retVal] || retVal;
}

return retVal;
};

/**
Expand Down