diff --git a/src/components/inputs/AutocompleteInput.jsx b/src/components/inputs/AutocompleteInput.jsx index a3611cc..65833c2 100644 --- a/src/components/inputs/AutocompleteInput.jsx +++ b/src/components/inputs/AutocompleteInput.jsx @@ -4,11 +4,72 @@ 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 ( +
{ + 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 +78,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 b2f6892..d8b898d 100644 --- a/src/components/layers/LayerSourceLayerBlock.jsx +++ b/src/components/layers/LayerSourceLayerBlock.jsx @@ -12,16 +12,19 @@ class LayerSourceLayer extends React.Component { value: PropTypes.string, onChange: PropTypes.func, sourceLayerIds: PropTypes.array, + isFixed: PropTypes.bool, } static defaultProps = { onChange: () => {}, sourceLayerIds: [], + isFixed: false } render() { return [l, l])} diff --git a/src/components/modals/AddModal.jsx b/src/components/modals/AddModal.jsx index ab4a6de..bb30a7c 100644 --- a/src/components/modals/AddModal.jsx +++ b/src/components/modals/AddModal.jsx @@ -127,6 +127,7 @@ class AddModal extends React.Component { } {this.state.type !== 'background' && this.state.type !== 'raster' && this.setState({ 'source-layer': v })}