Skip to content

Commit de03329

Browse files
committed
Support rtl in floating.tsx
1 parent fec4897 commit de03329

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/kit-headless/src/components/popover/floating.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,24 @@ export const FloatingPopover = component$((props: PropsOf<'div'>) => {
6161
}).then(async (resolvedData) => {
6262
const { x, y } = resolvedData;
6363

64-
Object.assign(popover.style, {
65-
left: `${x}px`,
66-
top: `${y}px`,
67-
transform: context.transform,
68-
});
64+
const isRTL = document.documentElement.dir === 'rtl';
65+
66+
if (isRTL) {
67+
const documentWidth = document.body.getBoundingClientRect().width;
68+
const popoverWidth = popover.getBoundingClientRect().width;
69+
70+
Object.assign(popover.style, {
71+
right: `${documentWidth - x - popoverWidth}px`,
72+
top: `${y}px`,
73+
transform: context.transform,
74+
});
75+
} else {
76+
Object.assign(popover.style, {
77+
left: `${x}px`,
78+
top: `${y}px`,
79+
transform: context.transform,
80+
});
81+
}
6982

7083
if (resolvedData.middlewareData.arrow && context.arrowRef?.value) {
7184
const { x, y } = resolvedData.middlewareData.arrow;

0 commit comments

Comments
 (0)