diff --git a/src/components/inputs/AutocompleteInput.jsx b/src/components/inputs/AutocompleteInput.jsx index a3611cce..6bd14e4d 100644 --- a/src/components/inputs/AutocompleteInput.jsx +++ b/src/components/inputs/AutocompleteInput.jsx @@ -4,11 +4,68 @@ import classnames from 'classnames' import Autocomplete from 'react-autocomplete' +class AutocompleteMenu extends React.Component { + static propTypes = { + keepMenuWithinWindowBounds: PropTypes.bool, + style: PropTypes.object, + children: PropTypes.none + } + + calcMaxHeight() { + if(this.props.keepMenuWithinWindowBounds) { + const maxHeight = window.innerHeight - this.autocompleteMenuEl.getBoundingClientRect().top; + if(maxHeight != this.state.maxHeight) { + this.setState({ + maxHeight: maxHeight + }) + } + } + } + componentDidMount() { + this.calcMaxHeight(); + } + + componentDidUpdate() { + this.calcMaxHeight(); + } + + constructor(props) { + super(props); + this.state = { + maxHeight: 90 + }; + } + + static defaultProps = { + style: {} + } + + render() { + const maxHeight = this.state.maxHeight - this.props.style.marginBottom || 0; + const style = { + maxHeight: maxHeight+"px" + } + + return ( +
{ + this.autocompleteMenuEl = el; + }} + className={"maputnik-autocomplete-menu"} + style={style} + > + {this.props.children} +
+ ) + } +} + class AutocompleteInput extends React.Component { static propTypes = { value: PropTypes.string, options: PropTypes.array, onChange: PropTypes.func, + keepMenuWithinWindowBounds: PropTypes.bool } static defaultProps = { @@ -17,14 +74,16 @@ class AutocompleteInput extends React.Component { } render() { - const AutocompleteMenu = (items, value, style) =>
{items}
- return { + return + {items} + + }} inputProps={{ className: "maputnik-string" }} diff --git a/src/components/layers/LayerSourceLayerBlock.jsx b/src/components/layers/LayerSourceLayerBlock.jsx index b2f68923..838ffd78 100644 --- a/src/components/layers/LayerSourceLayerBlock.jsx +++ b/src/components/layers/LayerSourceLayerBlock.jsx @@ -22,6 +22,7 @@ class LayerSourceLayer extends React.Component { render() { return [l, l])}