From 33fdc5266799edae44f41e721d03855eea6a278c Mon Sep 17 00:00:00 2001 From: orangemug Date: Wed, 29 Nov 2017 10:29:11 +0000 Subject: [PATCH] Added MAX_HEIGHT constant. --- src/components/inputs/AutocompleteInput.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/inputs/AutocompleteInput.jsx b/src/components/inputs/AutocompleteInput.jsx index 11e6d4d4..65833c23 100644 --- a/src/components/inputs/AutocompleteInput.jsx +++ b/src/components/inputs/AutocompleteInput.jsx @@ -4,6 +4,8 @@ import classnames from 'classnames' import Autocomplete from 'react-autocomplete' +const MAX_HEIGHT = 140; + class AutocompleteMenu extends React.Component { static propTypes = { keepMenuWithinWindowBounds: PropTypes.bool, @@ -14,9 +16,11 @@ class AutocompleteMenu extends React.Component { calcMaxHeight() { if(this.props.keepMenuWithinWindowBounds) { const maxHeight = window.innerHeight - this.autocompleteMenuEl.getBoundingClientRect().top; - if(maxHeight != this.state.maxHeight) { + const limitedMaxHeight = Math.min(maxHeight, MAX_HEIGHT); + + if(limitedMaxHeight != this.state.maxHeight) { this.setState({ - maxHeight: maxHeight + maxHeight: limitedMaxHeight }) } } @@ -32,7 +36,7 @@ class AutocompleteMenu extends React.Component { constructor(props) { super(props); this.state = { - maxHeight: 90 + maxHeight: MAX_HEIGHT }; }