Skip to content

Commit

Permalink
feat(popover): prevent flip (#398)
Browse files Browse the repository at this point in the history
* feat(popover): add preventFlip prop

* feat(select): prevent options-list flip
  • Loading branch information
reme3d2y committed Dec 2, 2020
1 parent d13c1f8 commit c0c1723
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/popover/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export type PopoverProps = {
*/
position?: Position;

/**
* Запрещает поповеру менять свою позицию.
* Например, если места снизу недостаточно,то он все равно будет показан снизу
*/
preventFlip?: boolean;

/**
* Если `true`, будет отрисована стрелочка
*/
Expand Down Expand Up @@ -89,6 +95,7 @@ export const Popover: React.FC<PopoverProps> = ({
withArrow = false,
withTransition = true,
position = 'left',
preventFlip,
popperClassName,
arrowClassName,
open,
Expand All @@ -105,8 +112,12 @@ export const Popover: React.FC<PopoverProps> = ({
modifiers.push({ name: 'arrow', options: { element: arrowElement } });
}

if (preventFlip) {
modifiers.push({ name: 'flip', options: { fallbackPlacements: [] } });
}

return modifiers;
}, [withArrow, arrowElement, offset]);
}, [offset, withArrow, preventFlip, arrowElement]);

const { styles: popperStyles, attributes, update } = usePopper(
referenceElement,
Expand Down
1 change: 1 addition & 0 deletions packages/select/src/components/base-select/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export const BaseSelect = forwardRef(
withTransition={false}
anchorElement={fieldRef.current as HTMLElement}
position='bottom-start'
preventFlip={true}
getPortalContainer={getPortalContainer}
popperClassName={styles.popover}
>
Expand Down

0 comments on commit c0c1723

Please sign in to comment.