Ensure single select boxes hide after choice selection

This commit is contained in:
Josh Johnson 2016-09-05 13:48:51 +01:00
parent cb3eeaf68e
commit 1f2d685f5e
4 changed files with 25 additions and 35 deletions

View file

@ -1,4 +1,4 @@
/*! choices.js v2.0.0 | (c) 2016 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v2.0.1 | (c) 2016 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
@ -855,11 +855,6 @@
console.error('callbackOnChange: Callback is not a function');
}
}
// Keep focus on select-one element
if (this.passedElement.type === 'select-one') {
this.containerOuter.focus();
}
}
/**
@ -958,6 +953,7 @@
// If we are clicking on an option
var id = element.getAttribute('data-id');
var choice = this.store.getChoiceById(id);
var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
if (choice && !choice.selected && !choice.disabled) {
var canAddItem = this._canAddItem(activeItems, choice.value);
@ -965,9 +961,16 @@
if (canAddItem.response) {
this._addItem(choice.value, choice.label, choice.id);
this._triggerChange(choice.value);
this.clearInput(this.passedElement);
}
}
this.clearInput(this.passedElement);
// We wont to close the dropdown if we are dealing with a single select box
if (hasActiveDropdown && this.passedElement.type === 'select-one') {
this.hideDropdown();
this.containerOuter.focus();
}
}
/**
@ -1026,7 +1029,7 @@
if (this.passedElement.type === 'text' && this.config.addItems) {
var isUnique = !activeItems.some(function (item) {
return item.value === value;
return item.value === value.trim();
});
// If a user has supplied a regular expression filter
@ -1236,14 +1239,6 @@
if (highlighted) {
_this15._handleChoiceAction(activeItems, highlighted);
}
// We always want to hide the dropdown for single selects
// regardless of whether an item was added
if (hasActiveDropdown && _this15.passedElement.type === 'select-one') {
_this15.hideDropdown();
_this15.clearInput();
_this15.containerOuter.focus();
}
} else if (_this15.passedElement.type === 'select-one') {
// Open single select dropdown if it's not active
if (!hasActiveDropdown) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -692,11 +692,6 @@ export default class Choices {
console.error('callbackOnChange: Callback is not a function');
}
}
// Keep focus on select-one element
if (this.passedElement.type === 'select-one') {
this.containerOuter.focus();
}
}
@ -775,6 +770,7 @@ export default class Choices {
// If we are clicking on an option
const id = element.getAttribute('data-id');
const choice = this.store.getChoiceById(id);
const hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
if (choice && !choice.selected && !choice.disabled) {
const canAddItem = this._canAddItem(activeItems, choice.value);
@ -782,9 +778,16 @@ export default class Choices {
if (canAddItem.response) {
this._addItem(choice.value, choice.label, choice.id);
this._triggerChange(choice.value);
this.clearInput(this.passedElement);
}
}
this.clearInput(this.passedElement);
// We wont to close the dropdown if we are dealing with a single select box
if (hasActiveDropdown && this.passedElement.type === 'select-one') {
this.hideDropdown();
this.containerOuter.focus();
}
}
/**
@ -832,7 +835,7 @@ export default class Choices {
}
if (this.passedElement.type === 'text' && this.config.addItems) {
const isUnique = !activeItems.some((item) => item.value === value);
const isUnique = !activeItems.some((item) => item.value === value.trim());
// If a user has supplied a regular expression filter
if (this.config.regexFilter) {
@ -1022,14 +1025,6 @@ export default class Choices {
if (highlighted) {
this._handleChoiceAction(activeItems, highlighted);
}
// We always want to hide the dropdown for single selects
// regardless of whether an item was added
if (hasActiveDropdown && this.passedElement.type === 'select-one') {
this.hideDropdown();
this.clearInput();
this.containerOuter.focus();
}
} else if (this.passedElement.type === 'select-one') {
// Open single select dropdown if it's not active
if (!hasActiveDropdown) {