From 5a714a31f29b4b464e4bcd8cefdcaadc1002b8bf Mon Sep 17 00:00:00 2001 From: Justin Reynolds Date: Thu, 28 Sep 2017 12:28:26 -0700 Subject: [PATCH] feat(core): Make HoverablePopover flip sides if there is not room to render on the provided side --- .../src/presentation/HoverablePopover.tsx | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/app/scripts/modules/core/src/presentation/HoverablePopover.tsx b/app/scripts/modules/core/src/presentation/HoverablePopover.tsx index 1954ce4c7a4..646e4ab3bac 100644 --- a/app/scripts/modules/core/src/presentation/HoverablePopover.tsx +++ b/app/scripts/modules/core/src/presentation/HoverablePopover.tsx @@ -34,8 +34,8 @@ export interface IHoverablePopoverProps { } export interface IHoverablePopoverState { + placementOverride?: Placement; popoverIsOpen: boolean; - target?: any; PopoverRenderer?: React.ComponentClass | React.StatelessComponent; } @@ -49,6 +49,8 @@ export class HoverablePopover extends React.Component>; private showHide$: Observable; private showHideSubscription: Subscription; @@ -141,8 +143,34 @@ export class HoverablePopover extends React.Component bounds.top && bounds.top < bottomSpace ? 'bottom' : undefined; + break; + case 'bottom': + placementOverride = clientHeight > bottomSpace && bottomSpace < bounds.top ? 'top' : undefined; + break; + case 'left': + placementOverride = clientWidth > bounds.left && bounds.left < rightSpace ? 'right' : undefined; + break; + case 'right': + placementOverride = clientWidth > rightSpace && rightSpace < bounds.left ? 'left' : undefined; + break; + } + this.setState({ placementOverride }); + } } public render() { @@ -152,8 +180,9 @@ export class HoverablePopover extends React.Component {this.props.children} - +