Skip to content

Commit

Permalink
fix: Update dropdown position logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeliwo committed Oct 30, 2019
1 parent 9adfa23 commit df50ca9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Dropdown/dropdownHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ export function getContentPositionStyle(
top: 'auto',
left: 'auto',
}
const triggerAlignCenter = triggerRect.left + (triggerRect.right - triggerRect.left) / 2

if (triggerRect.bottom + contentSize.height <= windowSize.height) {
position.top = `${scroll.top + triggerRect.bottom}px`
} else {
} else if (triggerRect.top - contentSize.height >= 0) {
position.top = `${scroll.top + triggerRect.top - contentSize.height}px`
} else {
position.top = `${scroll.top + triggerRect.bottom}px`
}

if (triggerRect.left + (triggerRect.right - triggerRect.left) / 2 <= windowSize.width / 2) {
if (triggerAlignCenter <= windowSize.width / 2) {
position.left = `${scroll.left + triggerRect.left}px`
} else {
} else if (triggerAlignCenter >= windowSize.width / 2) {
position.left = `${scroll.left + triggerRect.right - contentSize.width}px`
} else {
position.left = `${scroll.left + triggerRect.left}px`
}

return position
Expand Down

0 comments on commit df50ca9

Please sign in to comment.