Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1154 from metasfresh/dev-1140-hotfix
Browse files Browse the repository at this point in the history
Hotfixes for dropdown appearance logic #1140
  • Loading branch information
teosarca committed Aug 23, 2017
2 parents 5baabb1 + 63003ed commit 205d667
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/components/widget/List/RawList.js
Expand Up @@ -44,9 +44,11 @@ class RawList extends Component {
if (prevState.selected !== this.state.selected) {
list.length === 1 && this.handleSelect(list[0]);

!doNotOpenOnFocus && list.length > 1 && this.setState({
isOpen: true
});
if (!doNotOpenOnFocus && list.length > 1) {
this.setState({
isOpen: true
});
}
}
}

Expand Down Expand Up @@ -75,10 +77,22 @@ class RawList extends Component {
}

if (list.length > 0) {
this.setState({
dropdownList: dropdown.concat(list),
selected: defaultValue ? defaultValue : list[0]
});
let openDropdownState = {};

if (this.openDropdown && (list.length > 1)) {
this.openDropdown = false;
openDropdownState.isOpen = true;
}

this.setState(
Object.assign(
{
dropdownList: dropdown.concat(list),
selected: defaultValue ? defaultValue : list[0],
},
openDropdownState
)
);
}
}

Expand Down Expand Up @@ -150,7 +164,7 @@ class RawList extends Component {
}

let baseIndex = list.indexOf(selected);
if (baseIndex < 0) {
if (selected && (baseIndex < 0)) {
let selectedKey = Object.keys(selected)[0];

baseIndex = list.findIndex( (item) => Object.keys(item)[0] === selectedKey );
Expand Down Expand Up @@ -268,19 +282,15 @@ class RawList extends Component {
* on focus.
*/
handleClick = (e) => {
const {lookupList} = this.props;

if (!lookupList) {
e.preventDefault();
e.preventDefault();

const {onFocus, doNotOpenOnFocus} = this.props;
const { onFocus } = this.props;

onFocus && onFocus();
onFocus && onFocus();

doNotOpenOnFocus && this.setState({
isOpen: true
})
}
this.setState({
isOpen: true
});
}

handleFocus = (e) => {
Expand All @@ -292,9 +302,9 @@ class RawList extends Component {

onFocus && onFocus();

!doNotOpenOnFocus && !autofocus && this.setState({
isOpen: true
})
if (!doNotOpenOnFocus && !autofocus) {
this.openDropdown = true;
}
}

handleChange = (e) => {
Expand Down

0 comments on commit 205d667

Please sign in to comment.