Skip to content

Commit

Permalink
Allow event delegation of events on .tt-suggestion. Fixes #118.
Browse files Browse the repository at this point in the history
Remove suggestions from DOM only after the click event that originated
from a suggestion has bubbled to the root.
  • Loading branch information
Jake Harding committed Feb 5, 2014
1 parent a6e411d commit a97976e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ var Typeahead = (function() {
.onSync('queryChanged', this._onQueryChanged, this)
.onSync('whitespaceChanged', this._onWhitespaceChanged, this);

// HACK: prevents input blur on menu click
// https://github.com/twitter/typeahead.js/pull/351
// #351: prevents input blur on menu click
$menu.on('mousedown.tt', function($e) {
if (_.isMsie() && _.isMsie() < 9) {
$input[0].onbeforedeactivate = function() {
Expand Down Expand Up @@ -242,14 +241,13 @@ var Typeahead = (function() {
this.input.clearHint();
this.input.setQuery(datum.value);
this.input.setInputValue(datum.value, true);
this.dropdown.empty();
this.dropdown.close();

this._setLanguageDirection();

// in ie, focus is not a synchronous event, so when a selection
// is triggered by a click within the dropdown menu, we need to
// defer the closing of the dropdown otherwise it'll stay open
_.defer(_.bind(this.dropdown.close, this.dropdown));
// #118: allow click event to bubble up to the body before removing
// the suggestions otherwise we break event delegation
_.defer(_.bind(this.dropdown.empty, this.dropdown));

this.eventBus.trigger('selected', datum.raw, datum.datasetName);
},
Expand Down

0 comments on commit a97976e

Please sign in to comment.