Skip to content

Commit

Permalink
fix(Popover): fix rtl placement
Browse files Browse the repository at this point in the history
  • Loading branch information
amje committed Feb 1, 2024
1 parent 304054d commit ea8aaed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {Xmark} from '@gravity-ui/icons';

import {Button} from '../Button';
import {Icon} from '../Icon';
import type {PopupPlacement} from '../Popup';
import {Popup} from '../Popup';
import {useDirection} from '../theme';
import type {QAProps} from '../types';
import {warnOnce} from '../utils/warn';

Expand All @@ -28,7 +30,7 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
delayOpening,
delayClosing,
behavior = PopoverBehavior.Delayed,
placement = ['right', 'bottom'],
placement,
offset = {},
tooltipOffset,
tooltipClassName,
Expand Down Expand Up @@ -62,6 +64,7 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
},
ref,
) {
const direction = useDirection();
const controlRef = React.useRef<HTMLDivElement>(null);
const closedManually = React.useRef(false);
const shouldBeOpen = React.useRef(initialOpen);
Expand All @@ -86,6 +89,14 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
shouldBeOpen,
});

const popupPlacement = React.useMemo<PopupPlacement>(() => {
if (placement) {
return placement;
}

return direction === 'rtl' ? ['left', 'bottom'] : ['right', 'bottom'];
}, [direction, placement]);

React.useImperativeHandle(
ref,
() => ({
Expand Down Expand Up @@ -120,7 +131,7 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
)}
contentClassName={cnPopover('tooltip-popup-content', tooltipContentClassName)}
open={isOpen}
placement={placement}
placement={popupPlacement}
hasArrow={hasArrow}
offset={tooltipOffset}
onClose={anchorRef ? undefined : closeTooltip}
Expand Down
1 change: 0 additions & 1 deletion src/components/Popover/__stories__/Popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default {
disabled: false,
autoclosable: true,
openOnHover: true,
placement: ['right', 'bottom'],
hasArrow: true,
hasClose: false,
theme: 'info',
Expand Down

0 comments on commit ea8aaed

Please sign in to comment.