diff --git a/src/components/inputs/AutocompleteInput.jsx b/src/components/inputs/AutocompleteInput.jsx
index 65833c23..21879139 100644
--- a/src/components/inputs/AutocompleteInput.jsx
+++ b/src/components/inputs/AutocompleteInput.jsx
@@ -6,11 +6,24 @@ import Autocomplete from 'react-autocomplete'
const MAX_HEIGHT = 140;
-class AutocompleteMenu extends React.Component {
+class AutocompleteInput extends React.Component {
static propTypes = {
- keepMenuWithinWindowBounds: PropTypes.bool,
- style: PropTypes.object,
- children: PropTypes.node
+ value: PropTypes.string,
+ options: PropTypes.array,
+ onChange: PropTypes.func,
+ keepMenuWithinWindowBounds: PropTypes.bool
+ }
+
+ static defaultProps = {
+ onChange: () => {},
+ options: [],
+ }
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ maxHeight: MAX_HEIGHT
+ };
}
calcMaxHeight() {
@@ -33,81 +46,43 @@ class AutocompleteMenu extends React.Component {
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;
+ return
{
+ this.autocompleteMenuEl = el;
+ }}
+ >
+
- {this.props.children}
-
- )
- }
-}
-
-class AutocompleteInput extends React.Component {
- static propTypes = {
- value: PropTypes.string,
- options: PropTypes.array,
- onChange: PropTypes.func,
- keepMenuWithinWindowBounds: PropTypes.bool
- }
-
- static defaultProps = {
- onChange: () => {},
- options: [],
- }
-
- render() {
- return
{
- return
- {items}
-
- }}
- inputProps={{
- className: "maputnik-string"
- }}
- value={this.props.value}
- items={this.props.options}
- getItemValue={(item) => item[0]}
- onSelect={v => this.props.onChange(v)}
- onChange={(e, v) => this.props.onChange(v)}
- renderItem={(item, isHighlighted) => (
-
- {item[1]}
-
- )}
- />
+ wrapperProps={{
+ className: "maputnik-autocomplete",
+ style: null
+ }}
+ inputProps={{
+ className: "maputnik-string"
+ }}
+ value={this.props.value}
+ items={this.props.options}
+ getItemValue={(item) => item[0]}
+ onSelect={v => this.props.onChange(v)}
+ onChange={(e, v) => this.props.onChange(v)}
+ renderItem={(item, isHighlighted) => (
+
+ {item[1]}
+
+ )}
+ />
+
}
}
diff --git a/src/components/modals/AddModal.jsx b/src/components/modals/AddModal.jsx
index bb30a7c1..a32eb6bd 100644
--- a/src/components/modals/AddModal.jsx
+++ b/src/components/modals/AddModal.jsx
@@ -58,11 +58,22 @@ class AddModal extends React.Component {
componentWillUpdate(nextProps, nextState) {
// Check if source is valid for new type
- const availableSources = this.getSources(nextState.type);
+ const oldType = this.state.type;
+ const newType = nextState.type;
+
+ const availableSourcesOld = this.getSources(oldType);
+ const availableSourcesNew = this.getSources(newType);
+
if(
- this.state.source !== ""
- && availableSources.indexOf(this.state.source) < 0
+ // Type has changed
+ oldType !== newType
+ && this.state.source !== ""
+ // Was a valid source previously
+ && availableSourcesOld.indexOf(this.state.source) > -1
+ // And is not a valid source now
+ && availableSourcesNew.indexOf(nextState.source) < 0
) {
+ // Clear the source
this.setState({
source: ""
});