import React from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' import Autocomplete from 'react-autocomplete' const MAX_HEIGHT = 140; class AutocompleteMenu extends React.Component { static propTypes = { keepMenuWithinWindowBounds: PropTypes.bool, style: PropTypes.object, children: PropTypes.node } calcMaxHeight() { if(this.props.keepMenuWithinWindowBounds) { const maxHeight = window.innerHeight - this.autocompleteMenuEl.getBoundingClientRect().top; const limitedMaxHeight = Math.min(maxHeight, MAX_HEIGHT); if(limitedMaxHeight != this.state.maxHeight) { this.setState({ maxHeight: limitedMaxHeight }) } } } componentDidMount() { this.calcMaxHeight(); } componentDidUpdate() { this.calcMaxHeight(); } constructor(props) { super(props); this.state = { maxHeight: MAX_HEIGHT }; } static defaultProps = { style: {} } render() { const maxHeight = this.state.maxHeight - this.props.style.marginBottom || 0; const style = { maxHeight: maxHeight+"px" } return (