Skip to content

Commit

Permalink
issue 1619: Remove 'blur' event on combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerie Young committed Jan 12, 2021
1 parent 4dcb7df commit a32a1a6
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions examples/combobox/js/combobox-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ class ComboboxAutocomplete {
'focus',
this.onComboboxFocus.bind(this)
);
this.comboboxNode.addEventListener('blur', this.onComboboxBlur.bind(this));

document.body.addEventListener(
'mouseup',
this.onBackgroundMouseUp.bind(this),
true
);

// initialize pop up menu

Expand Down Expand Up @@ -507,11 +512,16 @@ class ComboboxAutocomplete {
this.setCurrentOptionStyle(null);
}

onComboboxBlur() {
this.comboboxHasVisualFocus = false;
this.setCurrentOptionStyle(null);
this.removeVisualFocusAll();
setTimeout(this.close.bind(this, false), 300);
onBackgroundMouseUp(event) {
if (
!this.comboboxNode.contains(event.target) &&
!this.listboxNode.contains(event.target)
) {
this.comboboxHasVisualFocus = false;
this.setCurrentOptionStyle(null);
this.removeVisualFocusAll();
setTimeout(this.close.bind(this, true), 300);
}
}

onButtonClick() {
Expand Down Expand Up @@ -564,6 +574,5 @@ window.addEventListener('load', function () {
var buttonNode = combobox.querySelector('button');
var listboxNode = combobox.querySelector('[role="listbox"]');
var cba = new ComboboxAutocomplete(comboboxNode, buttonNode, listboxNode);
cba.init();
}
});

0 comments on commit a32a1a6

Please sign in to comment.