Skip to content

Commit

Permalink
fix(Positioner): Correctly overflow bottom's (segmentio#570)
Browse files Browse the repository at this point in the history
* fix(Positioner): Correctly overflow bottom's

* test: Correctly unit test a shift up from the target

* chore: Added story for illustrating edge case
  • Loading branch information
maraisr authored and Matt Shwery committed Jun 17, 2019
1 parent fef0013 commit 947cf13
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/popover/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { Button } from '../../buttons'
import { Position } from '../../constants'
import { Icon, IconNames } from '../../icon'

const PopoverContent = () => (
// eslint-disable-next-line react/prop-types
const PopoverContent = ({ height = 240 }) => (
<Pane
width={240}
height={240}
height={height}
display="flex"
alignItems="center"
justifyContent="center"
Expand Down Expand Up @@ -172,6 +173,14 @@ storiesOf('popover', module)
Use Smart Positioning
</Button>
</Popover>
<Popover
content={<PopoverContent height={999} />}
position={Position.TOP_LEFT}
>
<Button position="absolute" left={40} top={80} marginRight={20}>
Compensated for shooting past the bottom
</Button>
</Popover>
</Box>
))
.add('auto focus text input', () => (
Expand Down
2 changes: 1 addition & 1 deletion src/positioner/src/getPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default function getFittedPosition({
if (rect.bottom > viewport.height - viewportOffset) {
const delta = Math.ceil(rect.bottom - (viewport.height - viewportOffset))
rect.top -= delta
rect.right -= delta
rect.bottom -= delta
}

const targetCenter = isAlignedHorizontal(position)
Expand Down
12 changes: 12 additions & 0 deletions src/positioner/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,15 @@ test('It pushes the rect to the right if overflowing on the left side', t => {
})
)
})

test('It pushes the rect to the top if overflowing on the bottom side', t => {
t.snapshot(
getFittedPosition({
position: Position.TOP,
dimensions: dimensions({ width: 50, height: 100 }),
targetRect: targetRect({ left: 100, x: 100, top: 550, y: 550 }),
targetOffset,
viewport: viewport({ height: 500 })
})
)
})
21 changes: 19 additions & 2 deletions src/positioner/test/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ Generated by [AVA](https://ava.li).
transformOrigin: '27px 0px ',
}

## It pushes the rect to the top if overflowing on the bottom side

> Snapshot 1
{
position: 'top',
rect: {
bottom: 492,
height: 100,
left: 100,
right: 150,
top: 392,
width: 50,
},
transformOrigin: '25px 100px ',
}

## Position.BOTTOM repositions to the top

> Snapshot 1
Expand Down Expand Up @@ -199,10 +216,10 @@ Generated by [AVA](https://ava.li).
{
position: 'bottom',
rect: {
bottom: 376,
bottom: 242,
height: 250,
left: 225,
right: 191,
right: 325,
top: -8,
width: 100,
},
Expand Down
Binary file modified src/positioner/test/snapshots/index.js.snap
Binary file not shown.

0 comments on commit 947cf13

Please sign in to comment.