Skip to content

Commit 97be94d

Browse files
authored
Merge pull request JedWatson#3205 from answerrocket/menu-flip-constraint
Menu: constrain to a maximum of maxHeight
2 parents 5094666 + 47939cf commit 97be94d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/components/Menu.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,13 @@ export function getMenuPlacement({
130130
if (placement === 'auto' || isFixedPosition) {
131131
// may need to be constrained after flipping
132132
let constrainedHeight = maxHeight;
133+
const spaceAbove = isFixedPosition ? viewSpaceAbove : scrollSpaceAbove;
133134

134-
if (
135-
(!isFixedPosition && scrollSpaceAbove >= minHeight) ||
136-
(isFixedPosition && viewSpaceAbove >= minHeight)
137-
) {
138-
constrainedHeight = isFixedPosition
139-
? viewSpaceAbove - marginBottom - spacing.controlHeight
140-
: scrollSpaceAbove - marginBottom - spacing.controlHeight;
135+
if (spaceAbove >= minHeight) {
136+
constrainedHeight = Math.min(
137+
spaceAbove - marginBottom - spacing.controlHeight,
138+
maxHeight
139+
);
141140
}
142141

143142
return { placement: 'top', maxHeight: constrainedHeight };

0 commit comments

Comments
 (0)