Skip to content
Open
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
6 changes: 2 additions & 4 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import {
Dimensions,
I18nManager,
Keyboard,
Platform,
Pressable,
Expand Down Expand Up @@ -30,7 +31,6 @@ import { scheduleOnRN } from 'react-native-worklets';
import useLatestCallback from 'use-latest-callback';

import MenuItem from './MenuItem';
import { useLocale } from '../../core/locale';
import { useInternalTheme } from '../../core/theming';
import { useMotionDuration } from '../../theme/accessibility/ReduceMotionContext';
import type { Elevation, ThemeProp } from '../../theme/types';
Expand Down Expand Up @@ -209,8 +209,6 @@ const Menu = ({
keyboardShouldPersistTaps,
}: Props) => {
const theme = useInternalTheme(themeOverrides);

const { direction } = useLocale();
const insets = useSafeAreaInsets();

const [rendered, setRendered] = React.useState(visible);
Expand Down Expand Up @@ -658,7 +656,7 @@ const Menu = ({
top: isCoordinate(anchor)
? topTransformation
: topTransformation + additionalVerticalValue,
...(direction === 'rtl'
...(Platform.OS !== 'web' && I18nManager.isRTL
? { right: leftTransformation }
: { left: leftTransformation }),
};
Expand Down
44 changes: 44 additions & 0 deletions src/components/__tests__/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,47 @@ it.each([
}
}
);

it('positions menu using left on web even in rtl direction', async () => {
const originalOS = Platform.OS;
const originalHTMLElement = (globalThis as { HTMLElement?: unknown })
.HTMLElement;
Platform.OS = 'web';
(globalThis as { HTMLElement?: unknown }).HTMLElement = class {};
const measureSpy = jest
.spyOn(ViewPrototype, 'measureInWindow')
.mockImplementation((fn) => fn(1133, 40, 130, 36));
const dimensionsSpy = jest
.spyOn(Dimensions, 'get')
.mockReturnValue({ width: 1280, height: 800, scale: 1, fontScale: 1 });

try {
await render(
<PaperProvider direction="rtl">
<Portal.Host>
<Menu
visible
onDismiss={jest.fn()}
anchor={<Button mode="outlined">Open menu</Button>}
testID="rtl-web-menu"
>
<Menu.Item onPress={jest.fn()} title="Copy" />
</Menu>
</Portal.Host>
</PaperProvider>
);

await act(async () => {
await jest.advanceTimersByTimeAsync(500);
});

const menu = screen.getByTestId('rtl-web-menu');
expect(menu.parent?.parent).toHaveStyle({ left: 1133 });
expect(menu.parent?.parent).not.toHaveStyle({ right: 1133 });
} finally {
Platform.OS = originalOS;
(globalThis as { HTMLElement?: unknown }).HTMLElement = originalHTMLElement;
measureSpy.mockRestore();
dimensionsSpy.mockRestore();
}
});
Loading