Skip to content

Commit d4dc396

Browse files
authored
fix(menu): correct RTL menu placement and arrow position (#1708)
Fixes RTL placement for: - `top-start` - `top-end` - `bottom-start` - `bottom-end`
1 parent 095d516 commit d4dc396

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

packages/dropdowns.next/src/elements/menu/MenuList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export const MenuList = forwardRef<HTMLUListElement, IMenuListProps>(
132132
>
133133
<StyledMenu
134134
data-garden-animate-arrow={isVisible}
135-
arrowPosition={hasArrow ? toArrowPosition(placement) : undefined}
135+
arrowPosition={hasArrow ? toArrowPosition(theme.rtl, placement) : undefined}
136136
isCompact={isCompact}
137137
minHeight={minHeight}
138138
maxHeight={maxHeight}

packages/dropdowns.next/src/elements/menu/utils.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,9 @@ export const toFloatingPlacement = (
7373
left: 'right',
7474
'left-start': 'right-start',
7575
'left-end': 'right-end',
76-
'top-start': 'top-end',
77-
'top-end': 'top-start',
7876
right: 'left',
7977
'right-start': 'left-start',
80-
'right-end': 'left-end',
81-
'bottom-start': 'bottom-end',
82-
'bottom-end': 'bottom-start'
78+
'right-end': 'left-end'
8379
};
8480

8581
retVal = placementMapRtl[retVal] || retVal;
@@ -138,11 +134,12 @@ export const toMenuPosition = (placement?: FloatingPlacement): MenuPosition => {
138134
/**
139135
* Convert Floating-UI placement to a valid `arrowStyles` position.
140136
*
137+
* @param isRtl Determines if layout is right-to-left.
141138
* @param placement A Floating-UI placement.
142139
*
143140
* @returns An `arrowStyles` position.
144141
*/
145-
export const toArrowPosition = (placement?: FloatingPlacement): ArrowPosition => {
142+
export const toArrowPosition = (isRtl: boolean, placement?: FloatingPlacement): ArrowPosition => {
146143
const positionMap: Record<FloatingPlacement, ArrowPosition> = {
147144
auto: 'top',
148145
top: 'bottom',
@@ -158,8 +155,20 @@ export const toArrowPosition = (placement?: FloatingPlacement): ArrowPosition =>
158155
'left-start': 'right-top',
159156
'left-end': 'right-bottom'
160157
};
158+
let retVal = positionMap[placement || 'auto'];
159+
160+
if (isRtl) {
161+
const rtlPositionMap: Record<string, ArrowPosition> = {
162+
'bottom-left': 'bottom-right',
163+
'bottom-right': 'bottom-left',
164+
'top-left': 'top-right',
165+
'top-right': 'top-left'
166+
};
161167

162-
return positionMap[placement || 'auto'];
168+
retVal = rtlPositionMap[retVal] || retVal;
169+
}
170+
171+
return retVal;
163172
};
164173

165174
/**

0 commit comments

Comments
 (0)