Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Oct 31, 2017
1 parent 9443a94 commit d80ae66
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export class Dropdown extends Component {
if(this.documentClickListener) {
this.selfClick = true;
}

if(!this.overlayClick) {
if(!this.overlayClick && !this.editableInputClick) {
this.focusInput.focus();

if(this.panel.offsetParent) {
Expand All @@ -108,6 +108,10 @@ export class Dropdown extends Component {
}
}
}

if(this.editableInputClick) {
this.expeditableInputClick = false;
}
}

panelClick() {
Expand Down Expand Up @@ -194,7 +198,7 @@ export class Dropdown extends Component {
}

onEditableInputClick(event) {
this.itemClick = true;
this.editableInputClick = true;
this.bindDocumentClickListener();
}

Expand All @@ -211,7 +215,6 @@ export class Dropdown extends Component {
}

onOptionClick(event) {
this.itemClick = true;
this.selectItem(event);
this.focusInput.focus();
this.hide();
Expand Down Expand Up @@ -270,6 +273,8 @@ export class Dropdown extends Component {

hide() {
this.panel.style.display = 'none';
this.unbindDocumentClickListener();
this.clearClickState();
}

alignPanel() {
Expand All @@ -282,14 +287,11 @@ export class Dropdown extends Component {
bindDocumentClickListener() {
if(!this.documentClickListener) {
this.documentClickListener = () => {
if(!this.selfClick && !this.itemClick && !this.overlayClick) {
if(!this.selfClick && !this.overlayClick) {
this.hide();
this.unbindDocumentClickListener();
}

this.selfClick = false;
this.itemClick = false;
this.overlayClick = false;
this.clearClickState();
};

document.addEventListener('click', this.documentClickListener);
Expand All @@ -303,6 +305,12 @@ export class Dropdown extends Component {
}
}

clearClickState() {
this.selfClick = false;
this.editableInputClick = false;
this.overlayClick = false;
}

updateEditableLabel(option): void {
if(this.editableInput) {
this.editableInput.value = (option ? this.getOptionLabel(option) : this.props.value||'');
Expand Down

0 comments on commit d80ae66

Please sign in to comment.