Skip to content

Commit

Permalink
improve blur handling and add option
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitiger committed Aug 8, 2016
1 parent 4436954 commit 3bb3453
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Selectize.defaults = {
preload: false,
allowEmptyOption: false,
closeAfterSelect: false,
blurAfterClose: false,

scrollDuration: 60,
loadThrottle: 300,
Expand Down
4 changes: 3 additions & 1 deletion src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,9 @@ $.extend(Selectize.prototype, {

self.isOpen = false;
self.$dropdown.hide();
self.$control_input.blur(); // close keyboard on iOS
if (self.settings.blurAfterClose) {
self.$control_input.blur(); // close keyboard on iOS
}
self.setActiveOption(null);
self.refreshState();

Expand Down
33 changes: 25 additions & 8 deletions test/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,34 @@

it('should close dropdown after selection made if closeAfterSelect: true', function(done) {
var test = setup_test('<select multiple>' +
'<option value="a">A</option>' +
'<option value="b">B</option>' +
'<option value="a">A</option>' +
'<option value="b">B</option>' +
'</select>', {closeAfterSelect: true});

click(test.selectize.$control, function() {
click($('[data-value=a]', test.selectize.$dropdown_content), function() {
expect(test.selectize.isOpen).to.be.equal(false);
expect(test.selectize.isFocused).to.be.equal(true);
done();
});
click(test.selectize.$control, function() {
click($('[data-value=a]', test.selectize.$dropdown_content), function() {
expect(test.selectize.isOpen).to.be.equal(false);
expect(test.selectize.isFocused).to.be.equal(true);
done();
});
});
});

it('should close dropdown after selection made if closeAfterSelect: true and blurAfterClose: true', function(done) {
var test = setup_test('<select multiple>' +
'<option value="a">A</option>' +
'<option value="b">B</option>' +
'</select>', {closeAfterSelect: true, blurAfterClose: true});

click(test.selectize.$control, function() {
expect(test.selectize.isOpen).to.be.equal(true);
expect(test.selectize.isFocused).to.be.equal(true);
click($('[data-value=a]', test.selectize.$dropdown_content), function() {
expect(test.selectize.isOpen).to.be.equal(false);
expect(test.selectize.isFocused).to.be.equal(false);
done();
});
});
});

describe('clicking control', function() {
Expand Down

0 comments on commit 3bb3453

Please sign in to comment.