mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-12 19:02:19 +02:00
Ensure single select boxes hide after choice selection
This commit is contained in:
parent
cb3eeaf68e
commit
1f2d685f5e
27
assets/scripts/dist/choices.js
vendored
27
assets/scripts/dist/choices.js
vendored
|
@ -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
|
/******/ (function(modules) { // webpackBootstrap
|
||||||
/******/ // The module cache
|
/******/ // The module cache
|
||||||
/******/ var installedModules = {};
|
/******/ var installedModules = {};
|
||||||
|
@ -855,11 +855,6 @@
|
||||||
console.error('callbackOnChange: Callback is not a function');
|
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
|
// If we are clicking on an option
|
||||||
var id = element.getAttribute('data-id');
|
var id = element.getAttribute('data-id');
|
||||||
var choice = this.store.getChoiceById(id);
|
var choice = this.store.getChoiceById(id);
|
||||||
|
var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
|
||||||
|
|
||||||
if (choice && !choice.selected && !choice.disabled) {
|
if (choice && !choice.selected && !choice.disabled) {
|
||||||
var canAddItem = this._canAddItem(activeItems, choice.value);
|
var canAddItem = this._canAddItem(activeItems, choice.value);
|
||||||
|
@ -965,9 +961,16 @@
|
||||||
if (canAddItem.response) {
|
if (canAddItem.response) {
|
||||||
this._addItem(choice.value, choice.label, choice.id);
|
this._addItem(choice.value, choice.label, choice.id);
|
||||||
this._triggerChange(choice.value);
|
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) {
|
if (this.passedElement.type === 'text' && this.config.addItems) {
|
||||||
var isUnique = !activeItems.some(function (item) {
|
var isUnique = !activeItems.some(function (item) {
|
||||||
return item.value === value;
|
return item.value === value.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
// If a user has supplied a regular expression filter
|
// If a user has supplied a regular expression filter
|
||||||
|
@ -1236,14 +1239,6 @@
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
_this15._handleChoiceAction(activeItems, 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') {
|
} else if (_this15.passedElement.type === 'select-one') {
|
||||||
// Open single select dropdown if it's not active
|
// Open single select dropdown if it's not active
|
||||||
if (!hasActiveDropdown) {
|
if (!hasActiveDropdown) {
|
||||||
|
|
2
assets/scripts/dist/choices.js.map
vendored
2
assets/scripts/dist/choices.js.map
vendored
File diff suppressed because one or more lines are too long
6
assets/scripts/dist/choices.min.js
vendored
6
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -692,11 +692,6 @@ export default class Choices {
|
||||||
console.error('callbackOnChange: Callback is not a function');
|
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
|
// If we are clicking on an option
|
||||||
const id = element.getAttribute('data-id');
|
const id = element.getAttribute('data-id');
|
||||||
const choice = this.store.getChoiceById(id);
|
const choice = this.store.getChoiceById(id);
|
||||||
|
const hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
|
||||||
|
|
||||||
if (choice && !choice.selected && !choice.disabled) {
|
if (choice && !choice.selected && !choice.disabled) {
|
||||||
const canAddItem = this._canAddItem(activeItems, choice.value);
|
const canAddItem = this._canAddItem(activeItems, choice.value);
|
||||||
|
@ -782,9 +778,16 @@ export default class Choices {
|
||||||
if (canAddItem.response) {
|
if (canAddItem.response) {
|
||||||
this._addItem(choice.value, choice.label, choice.id);
|
this._addItem(choice.value, choice.label, choice.id);
|
||||||
this._triggerChange(choice.value);
|
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) {
|
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 a user has supplied a regular expression filter
|
||||||
if (this.config.regexFilter) {
|
if (this.config.regexFilter) {
|
||||||
|
@ -1022,14 +1025,6 @@ export default class Choices {
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
this._handleChoiceAction(activeItems, 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') {
|
} else if (this.passedElement.type === 'select-one') {
|
||||||
// Open single select dropdown if it's not active
|
// Open single select dropdown if it's not active
|
||||||
if (!hasActiveDropdown) {
|
if (!hasActiveDropdown) {
|
||||||
|
|
Loading…
Reference in a new issue