Skip to content

Commit

Permalink
fix: Fix dropdown content position
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeliwo committed Oct 31, 2019
1 parent f871699 commit e7465c3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/Dropdown/dropdownHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@ export function getContentBoxStyle(
left: 'auto',
maxHeight: '',
}
const triggerAlignCenter = triggerRect.left + (triggerRect.right - triggerRect.left) / 2

if (triggerRect.bottom + contentSize.height <= windowSize.height) {
contentBox.top = `${scroll.top + triggerRect.bottom}px`
} else if (triggerRect.top - contentSize.height >= 0) {
contentBox.top = `${scroll.top + triggerRect.top - contentSize.height}px`
} else {
const paddingBottom = 10
contentBox.top = `${scroll.top + triggerRect.bottom}px`
contentBox.maxHeight = `${windowSize.height - triggerRect.bottom - paddingBottom}px`
const padding = 10

if (triggerRect.top + (triggerRect.bottom - triggerRect.top) / 2 < windowSize.height / 2) {
contentBox.top = `${scroll.top + triggerRect.bottom}px`
contentBox.maxHeight = `${windowSize.height - triggerRect.bottom - padding}px`
} else {
contentBox.top = `${scroll.top + padding}px`
contentBox.maxHeight = `${triggerRect.top - padding}px`
}
}

const triggerAlignCenter = triggerRect.left + (triggerRect.right - triggerRect.left) / 2

if (triggerAlignCenter <= windowSize.width / 2) {
contentBox.left = `${scroll.left + triggerRect.left}px`
} else if (triggerAlignCenter >= windowSize.width / 2) {
Expand Down

0 comments on commit e7465c3

Please sign in to comment.