Skip to content

Commit

Permalink
selectOnClose now properly works with closeOnSelect
Browse files Browse the repository at this point in the history
Previously we hacked around the infinite loop between closeOnSelect and
selectOnClose by attempting to detect what event was being triggered
without knowing what event triggered it. Now we properly relay the
Select2 event and the jQuery event that triggered the select or unselect

This closes select2#4012
  • Loading branch information
kevin-brown committed May 15, 2016
1 parent ad8447c commit 481c438
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/js/select2/dropdown/closeOnSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ define([
return;
}

this.trigger('close', {});
this.trigger('close', {
originalEvent: originalEvent,
originalSelect2Event: evt
});
};

return CloseOnSelect;
Expand Down
16 changes: 13 additions & 3 deletions src/js/select2/dropdown/selectOnClose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ define([

decorated.call(this, container, $container);

container.on('close', function () {
self._handleSelectOnClose();
container.on('close', function (params) {
self._handleSelectOnClose(params);
});
};

SelectOnClose.prototype._handleSelectOnClose = function () {
SelectOnClose.prototype._handleSelectOnClose = function (_, params) {
if (params && params.originalSelect2Event != null) {
var event = params.originalSelect2Event;

// Don't select an item if the close event was triggered from a select or
// unselect event
if (event._type === 'select' || event._type === 'unselect') {
return;
}
}

var $highlightedResults = this.getHighlightedResults();

// Only select highlighted results
Expand Down

0 comments on commit 481c438

Please sign in to comment.