This commit is contained in:
Xon 2024-12-27 18:54:12 +00:00
commit 4e540c9d22
11 changed files with 404 additions and 228 deletions

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.2 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v11.0.3 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@ -89,6 +89,20 @@
unhighlightItem: 'unhighlightItem',
};
var KeyCodeMap = {
TAB_KEY: 9,
SHIFT_KEY: 16,
BACK_KEY: 46,
DELETE_KEY: 8,
ENTER_KEY: 13,
A_KEY: 65,
ESC_KEY: 27,
UP_KEY: 38,
DOWN_KEY: 40,
PAGE_UP_KEY: 33,
PAGE_DOWN_KEY: 34,
};
var ObjectsInConfig = ['fuseOptions', 'classNames'];
var PassedElementTypes = {
@ -745,11 +759,15 @@
}
return undefined;
};
var mapInputToChoice = function (value, allowGroup) {
var mapInputToChoice = function (value, allowGroup, allowRawString) {
if (allowRawString === void 0) { allowRawString = true; }
if (typeof value === 'string') {
var sanitisedValue = sanitise(value);
var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
var result_1 = mapInputToChoice({
value: value,
label: value,
label: userValue,
selected: true,
}, false);
return result_1;
}
@ -854,7 +872,7 @@
score: 0,
rank: 0,
value: option.value,
label: option.innerHTML,
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
element: option,
active: true,
// this returns true if nothing is selected on initial load, which will break placeholder support
@ -3613,11 +3631,15 @@
if (this.dropdown.isActive) {
return this;
}
if (preventInputFocus === undefined) {
// eslint-disable-next-line no-param-reassign
preventInputFocus = !this._canSearch;
}
requestAnimationFrame(function () {
_this.dropdown.show();
var rect = _this.dropdown.element.getBoundingClientRect();
_this.containerOuter.open(rect.bottom, rect.height);
if (!preventInputFocus && _this._canSearch) {
if (!preventInputFocus) {
_this.input.focus();
}
_this.passedElement.triggerEvent(EventType.showDropdown);
@ -3919,6 +3941,7 @@
}
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
@ -4300,6 +4323,7 @@
};
Choices.prototype._loadChoices = function () {
var _a;
var _this = this;
var config = this.config;
if (this._isTextElement) {
// Assign preset items from passed object first
@ -4308,7 +4332,7 @@
if (this.passedElement.value) {
var elementItems = this.passedElement.value
.split(config.delimiter)
.map(function (e) { return mapInputToChoice(e, false); });
.map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); });
this._presetChoices = this._presetChoices.concat(elementItems);
}
this._presetChoices.forEach(function (choice) {
@ -4374,6 +4398,7 @@
var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText;
if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) {
this.choiceList.element.replaceChildren('');
this._notice = undefined;
this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice);
return false;
}
@ -4551,7 +4576,15 @@
var wasPrintableChar = event.key.length === 1 ||
(event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) ||
event.key === 'Unidentified';
if (!this._isTextElement && !hasActiveDropdown) {
/*
We do not show the dropdown if focusing out with esc or navigating through input fields.
An activated search can still be opened with any other key.
*/
if (!this._isTextElement &&
!hasActiveDropdown &&
keyCode !== KeyCodeMap.ESC_KEY &&
keyCode !== KeyCodeMap.TAB_KEY &&
keyCode !== KeyCodeMap.SHIFT_KEY) {
this.showDropdown();
if (!this.input.isFocussed && wasPrintableChar) {
/*
@ -4567,19 +4600,19 @@
}
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
case KeyCodeMap.ESC_KEY:
return this._onEscapeKey(event, hasActiveDropdown);
case 38 /* KeyCodeMap.UP_KEY */:
case 33 /* KeyCodeMap.PAGE_UP_KEY */:
case 40 /* KeyCodeMap.DOWN_KEY */:
case 34 /* KeyCodeMap.PAGE_DOWN_KEY */:
case KeyCodeMap.UP_KEY:
case KeyCodeMap.PAGE_UP_KEY:
case KeyCodeMap.DOWN_KEY:
case KeyCodeMap.PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
@ -4660,13 +4693,7 @@
if (!_this._canCreateItem(value)) {
return;
}
var sanitisedValue = sanitise(value);
var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
_this._addChoice(mapInputToChoice({
value: userValue,
label: userValue,
selected: true,
}, false), true, true);
_this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true);
addedItem = true;
}
_this.clearInput();
@ -4684,6 +4711,7 @@
if (hasActiveDropdown) {
event.stopPropagation();
this.hideDropdown(true);
this._stopSearch();
this.containerOuter.element.focus();
}
};
@ -4693,8 +4721,8 @@
if (hasActiveDropdown || this._isSelectOneElement) {
this.showDropdown();
this._canSearch = false;
var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1;
var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */;
var directionInt = keyCode === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1;
var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY;
var nextEl = void 0;
if (skipKey) {
if (directionInt > 0) {
@ -4859,19 +4887,16 @@
var containerOuter = this.containerOuter;
var blurWasWithinContainer = target && containerOuter.element.contains(target);
if (blurWasWithinContainer && !this._isScrollingOnIe) {
var targetIsInput = target === this.input.element;
if (this._isTextElement || this._isSelectMultipleElement) {
if (targetIsInput) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (target === this.input.element) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (this._isTextElement || this._isSelectMultipleElement) {
this.unhighlightAll();
}
}
else {
else if (target === this.containerOuter.element) {
// Remove the focus state when the past outerContainer was the target
containerOuter.removeFocusState();
if (targetIsInput || (target === containerOuter.element && !this._canSearch)) {
this.hideDropdown(true);
}
}
}
else {
@ -4958,6 +4983,10 @@
return;
}
this._store.dispatch(removeItem$1(item));
var notice = this._notice;
if (notice && notice.type === NoticeTypes.noChoices) {
this._clearNotice();
}
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
};
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
@ -5174,7 +5203,7 @@
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
}
};
Choices.version = '11.0.2';
Choices.version = '11.0.3';
return Choices;
}());

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.2 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v11.0.3 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/******************************************************************************
Copyright (c) Microsoft Corporation.
@ -83,6 +83,20 @@ var EventType = {
unhighlightItem: 'unhighlightItem',
};
var KeyCodeMap = {
TAB_KEY: 9,
SHIFT_KEY: 16,
BACK_KEY: 46,
DELETE_KEY: 8,
ENTER_KEY: 13,
A_KEY: 65,
ESC_KEY: 27,
UP_KEY: 38,
DOWN_KEY: 40,
PAGE_UP_KEY: 33,
PAGE_DOWN_KEY: 34,
};
var ObjectsInConfig = ['fuseOptions', 'classNames'];
var PassedElementTypes = {
@ -739,11 +753,15 @@ var stringToHtmlClass = function (input) {
}
return undefined;
};
var mapInputToChoice = function (value, allowGroup) {
var mapInputToChoice = function (value, allowGroup, allowRawString) {
if (allowRawString === void 0) { allowRawString = true; }
if (typeof value === 'string') {
var sanitisedValue = sanitise(value);
var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
var result_1 = mapInputToChoice({
value: value,
label: value,
label: userValue,
selected: true,
}, false);
return result_1;
}
@ -848,7 +866,7 @@ var WrappedSelect = /** @class */ (function (_super) {
score: 0,
rank: 0,
value: option.value,
label: option.innerHTML,
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
element: option,
active: true,
// this returns true if nothing is selected on initial load, which will break placeholder support
@ -3607,11 +3625,15 @@ var Choices = /** @class */ (function () {
if (this.dropdown.isActive) {
return this;
}
if (preventInputFocus === undefined) {
// eslint-disable-next-line no-param-reassign
preventInputFocus = !this._canSearch;
}
requestAnimationFrame(function () {
_this.dropdown.show();
var rect = _this.dropdown.element.getBoundingClientRect();
_this.containerOuter.open(rect.bottom, rect.height);
if (!preventInputFocus && _this._canSearch) {
if (!preventInputFocus) {
_this.input.focus();
}
_this.passedElement.triggerEvent(EventType.showDropdown);
@ -3913,6 +3935,7 @@ var Choices = /** @class */ (function () {
}
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
@ -4294,6 +4317,7 @@ var Choices = /** @class */ (function () {
};
Choices.prototype._loadChoices = function () {
var _a;
var _this = this;
var config = this.config;
if (this._isTextElement) {
// Assign preset items from passed object first
@ -4302,7 +4326,7 @@ var Choices = /** @class */ (function () {
if (this.passedElement.value) {
var elementItems = this.passedElement.value
.split(config.delimiter)
.map(function (e) { return mapInputToChoice(e, false); });
.map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); });
this._presetChoices = this._presetChoices.concat(elementItems);
}
this._presetChoices.forEach(function (choice) {
@ -4368,6 +4392,7 @@ var Choices = /** @class */ (function () {
var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText;
if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) {
this.choiceList.element.replaceChildren('');
this._notice = undefined;
this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice);
return false;
}
@ -4545,7 +4570,15 @@ var Choices = /** @class */ (function () {
var wasPrintableChar = event.key.length === 1 ||
(event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) ||
event.key === 'Unidentified';
if (!this._isTextElement && !hasActiveDropdown) {
/*
We do not show the dropdown if focusing out with esc or navigating through input fields.
An activated search can still be opened with any other key.
*/
if (!this._isTextElement &&
!hasActiveDropdown &&
keyCode !== KeyCodeMap.ESC_KEY &&
keyCode !== KeyCodeMap.TAB_KEY &&
keyCode !== KeyCodeMap.SHIFT_KEY) {
this.showDropdown();
if (!this.input.isFocussed && wasPrintableChar) {
/*
@ -4561,19 +4594,19 @@ var Choices = /** @class */ (function () {
}
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
case KeyCodeMap.ESC_KEY:
return this._onEscapeKey(event, hasActiveDropdown);
case 38 /* KeyCodeMap.UP_KEY */:
case 33 /* KeyCodeMap.PAGE_UP_KEY */:
case 40 /* KeyCodeMap.DOWN_KEY */:
case 34 /* KeyCodeMap.PAGE_DOWN_KEY */:
case KeyCodeMap.UP_KEY:
case KeyCodeMap.PAGE_UP_KEY:
case KeyCodeMap.DOWN_KEY:
case KeyCodeMap.PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
@ -4654,13 +4687,7 @@ var Choices = /** @class */ (function () {
if (!_this._canCreateItem(value)) {
return;
}
var sanitisedValue = sanitise(value);
var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
_this._addChoice(mapInputToChoice({
value: userValue,
label: userValue,
selected: true,
}, false), true, true);
_this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true);
addedItem = true;
}
_this.clearInput();
@ -4678,6 +4705,7 @@ var Choices = /** @class */ (function () {
if (hasActiveDropdown) {
event.stopPropagation();
this.hideDropdown(true);
this._stopSearch();
this.containerOuter.element.focus();
}
};
@ -4687,8 +4715,8 @@ var Choices = /** @class */ (function () {
if (hasActiveDropdown || this._isSelectOneElement) {
this.showDropdown();
this._canSearch = false;
var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1;
var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */;
var directionInt = keyCode === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1;
var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY;
var nextEl = void 0;
if (skipKey) {
if (directionInt > 0) {
@ -4853,19 +4881,16 @@ var Choices = /** @class */ (function () {
var containerOuter = this.containerOuter;
var blurWasWithinContainer = target && containerOuter.element.contains(target);
if (blurWasWithinContainer && !this._isScrollingOnIe) {
var targetIsInput = target === this.input.element;
if (this._isTextElement || this._isSelectMultipleElement) {
if (targetIsInput) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (target === this.input.element) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (this._isTextElement || this._isSelectMultipleElement) {
this.unhighlightAll();
}
}
else {
else if (target === this.containerOuter.element) {
// Remove the focus state when the past outerContainer was the target
containerOuter.removeFocusState();
if (targetIsInput || (target === containerOuter.element && !this._canSearch)) {
this.hideDropdown(true);
}
}
}
else {
@ -4952,6 +4977,10 @@ var Choices = /** @class */ (function () {
return;
}
this._store.dispatch(removeItem$1(item));
var notice = this._notice;
if (notice && notice.type === NoticeTypes.noChoices) {
this._clearNotice();
}
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
};
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
@ -5168,7 +5197,7 @@ var Choices = /** @class */ (function () {
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
}
};
Choices.version = '11.0.2';
Choices.version = '11.0.3';
return Choices;
}());

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.2 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v11.0.3 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@ -89,6 +89,20 @@
unhighlightItem: 'unhighlightItem',
};
var KeyCodeMap = {
TAB_KEY: 9,
SHIFT_KEY: 16,
BACK_KEY: 46,
DELETE_KEY: 8,
ENTER_KEY: 13,
A_KEY: 65,
ESC_KEY: 27,
UP_KEY: 38,
DOWN_KEY: 40,
PAGE_UP_KEY: 33,
PAGE_DOWN_KEY: 34,
};
var ObjectsInConfig = ['fuseOptions', 'classNames'];
var PassedElementTypes = {
@ -745,11 +759,15 @@
}
return undefined;
};
var mapInputToChoice = function (value, allowGroup) {
var mapInputToChoice = function (value, allowGroup, allowRawString) {
if (allowRawString === void 0) { allowRawString = true; }
if (typeof value === 'string') {
var sanitisedValue = sanitise(value);
var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
var result_1 = mapInputToChoice({
value: value,
label: value,
label: userValue,
selected: true,
}, false);
return result_1;
}
@ -854,7 +872,7 @@
score: 0,
rank: 0,
value: option.value,
label: option.innerHTML,
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
element: option,
active: true,
// this returns true if nothing is selected on initial load, which will break placeholder support
@ -3131,11 +3149,15 @@
if (this.dropdown.isActive) {
return this;
}
if (preventInputFocus === undefined) {
// eslint-disable-next-line no-param-reassign
preventInputFocus = !this._canSearch;
}
requestAnimationFrame(function () {
_this.dropdown.show();
var rect = _this.dropdown.element.getBoundingClientRect();
_this.containerOuter.open(rect.bottom, rect.height);
if (!preventInputFocus && _this._canSearch) {
if (!preventInputFocus) {
_this.input.focus();
}
_this.passedElement.triggerEvent(EventType.showDropdown);
@ -3437,6 +3459,7 @@
}
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
@ -3818,6 +3841,7 @@
};
Choices.prototype._loadChoices = function () {
var _a;
var _this = this;
var config = this.config;
if (this._isTextElement) {
// Assign preset items from passed object first
@ -3826,7 +3850,7 @@
if (this.passedElement.value) {
var elementItems = this.passedElement.value
.split(config.delimiter)
.map(function (e) { return mapInputToChoice(e, false); });
.map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); });
this._presetChoices = this._presetChoices.concat(elementItems);
}
this._presetChoices.forEach(function (choice) {
@ -3892,6 +3916,7 @@
var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText;
if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) {
this.choiceList.element.replaceChildren('');
this._notice = undefined;
this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice);
return false;
}
@ -4069,7 +4094,15 @@
var wasPrintableChar = event.key.length === 1 ||
(event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) ||
event.key === 'Unidentified';
if (!this._isTextElement && !hasActiveDropdown) {
/*
We do not show the dropdown if focusing out with esc or navigating through input fields.
An activated search can still be opened with any other key.
*/
if (!this._isTextElement &&
!hasActiveDropdown &&
keyCode !== KeyCodeMap.ESC_KEY &&
keyCode !== KeyCodeMap.TAB_KEY &&
keyCode !== KeyCodeMap.SHIFT_KEY) {
this.showDropdown();
if (!this.input.isFocussed && wasPrintableChar) {
/*
@ -4085,19 +4118,19 @@
}
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
case KeyCodeMap.ESC_KEY:
return this._onEscapeKey(event, hasActiveDropdown);
case 38 /* KeyCodeMap.UP_KEY */:
case 33 /* KeyCodeMap.PAGE_UP_KEY */:
case 40 /* KeyCodeMap.DOWN_KEY */:
case 34 /* KeyCodeMap.PAGE_DOWN_KEY */:
case KeyCodeMap.UP_KEY:
case KeyCodeMap.PAGE_UP_KEY:
case KeyCodeMap.DOWN_KEY:
case KeyCodeMap.PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
@ -4178,13 +4211,7 @@
if (!_this._canCreateItem(value)) {
return;
}
var sanitisedValue = sanitise(value);
var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
_this._addChoice(mapInputToChoice({
value: userValue,
label: userValue,
selected: true,
}, false), true, true);
_this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true);
addedItem = true;
}
_this.clearInput();
@ -4202,6 +4229,7 @@
if (hasActiveDropdown) {
event.stopPropagation();
this.hideDropdown(true);
this._stopSearch();
this.containerOuter.element.focus();
}
};
@ -4211,8 +4239,8 @@
if (hasActiveDropdown || this._isSelectOneElement) {
this.showDropdown();
this._canSearch = false;
var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1;
var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */;
var directionInt = keyCode === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1;
var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY;
var nextEl = void 0;
if (skipKey) {
if (directionInt > 0) {
@ -4377,19 +4405,16 @@
var containerOuter = this.containerOuter;
var blurWasWithinContainer = target && containerOuter.element.contains(target);
if (blurWasWithinContainer && !this._isScrollingOnIe) {
var targetIsInput = target === this.input.element;
if (this._isTextElement || this._isSelectMultipleElement) {
if (targetIsInput) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (target === this.input.element) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (this._isTextElement || this._isSelectMultipleElement) {
this.unhighlightAll();
}
}
else {
else if (target === this.containerOuter.element) {
// Remove the focus state when the past outerContainer was the target
containerOuter.removeFocusState();
if (targetIsInput || (target === containerOuter.element && !this._canSearch)) {
this.hideDropdown(true);
}
}
}
else {
@ -4476,6 +4501,10 @@
return;
}
this._store.dispatch(removeItem$1(item));
var notice = this._notice;
if (notice && notice.type === NoticeTypes.noChoices) {
this._clearNotice();
}
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
};
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
@ -4692,7 +4721,7 @@
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
}
};
Choices.version = '11.0.2';
Choices.version = '11.0.3';
return Choices;
}());

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.2 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v11.0.3 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/******************************************************************************
Copyright (c) Microsoft Corporation.
@ -83,6 +83,20 @@ var EventType = {
unhighlightItem: 'unhighlightItem',
};
var KeyCodeMap = {
TAB_KEY: 9,
SHIFT_KEY: 16,
BACK_KEY: 46,
DELETE_KEY: 8,
ENTER_KEY: 13,
A_KEY: 65,
ESC_KEY: 27,
UP_KEY: 38,
DOWN_KEY: 40,
PAGE_UP_KEY: 33,
PAGE_DOWN_KEY: 34,
};
var ObjectsInConfig = ['fuseOptions', 'classNames'];
var PassedElementTypes = {
@ -739,11 +753,15 @@ var stringToHtmlClass = function (input) {
}
return undefined;
};
var mapInputToChoice = function (value, allowGroup) {
var mapInputToChoice = function (value, allowGroup, allowRawString) {
if (allowRawString === void 0) { allowRawString = true; }
if (typeof value === 'string') {
var sanitisedValue = sanitise(value);
var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
var result_1 = mapInputToChoice({
value: value,
label: value,
label: userValue,
selected: true,
}, false);
return result_1;
}
@ -848,7 +866,7 @@ var WrappedSelect = /** @class */ (function (_super) {
score: 0,
rank: 0,
value: option.value,
label: option.innerHTML,
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
element: option,
active: true,
// this returns true if nothing is selected on initial load, which will break placeholder support
@ -3125,11 +3143,15 @@ var Choices = /** @class */ (function () {
if (this.dropdown.isActive) {
return this;
}
if (preventInputFocus === undefined) {
// eslint-disable-next-line no-param-reassign
preventInputFocus = !this._canSearch;
}
requestAnimationFrame(function () {
_this.dropdown.show();
var rect = _this.dropdown.element.getBoundingClientRect();
_this.containerOuter.open(rect.bottom, rect.height);
if (!preventInputFocus && _this._canSearch) {
if (!preventInputFocus) {
_this.input.focus();
}
_this.passedElement.triggerEvent(EventType.showDropdown);
@ -3431,6 +3453,7 @@ var Choices = /** @class */ (function () {
}
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
@ -3812,6 +3835,7 @@ var Choices = /** @class */ (function () {
};
Choices.prototype._loadChoices = function () {
var _a;
var _this = this;
var config = this.config;
if (this._isTextElement) {
// Assign preset items from passed object first
@ -3820,7 +3844,7 @@ var Choices = /** @class */ (function () {
if (this.passedElement.value) {
var elementItems = this.passedElement.value
.split(config.delimiter)
.map(function (e) { return mapInputToChoice(e, false); });
.map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); });
this._presetChoices = this._presetChoices.concat(elementItems);
}
this._presetChoices.forEach(function (choice) {
@ -3886,6 +3910,7 @@ var Choices = /** @class */ (function () {
var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText;
if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) {
this.choiceList.element.replaceChildren('');
this._notice = undefined;
this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice);
return false;
}
@ -4063,7 +4088,15 @@ var Choices = /** @class */ (function () {
var wasPrintableChar = event.key.length === 1 ||
(event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) ||
event.key === 'Unidentified';
if (!this._isTextElement && !hasActiveDropdown) {
/*
We do not show the dropdown if focusing out with esc or navigating through input fields.
An activated search can still be opened with any other key.
*/
if (!this._isTextElement &&
!hasActiveDropdown &&
keyCode !== KeyCodeMap.ESC_KEY &&
keyCode !== KeyCodeMap.TAB_KEY &&
keyCode !== KeyCodeMap.SHIFT_KEY) {
this.showDropdown();
if (!this.input.isFocussed && wasPrintableChar) {
/*
@ -4079,19 +4112,19 @@ var Choices = /** @class */ (function () {
}
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
case KeyCodeMap.ESC_KEY:
return this._onEscapeKey(event, hasActiveDropdown);
case 38 /* KeyCodeMap.UP_KEY */:
case 33 /* KeyCodeMap.PAGE_UP_KEY */:
case 40 /* KeyCodeMap.DOWN_KEY */:
case 34 /* KeyCodeMap.PAGE_DOWN_KEY */:
case KeyCodeMap.UP_KEY:
case KeyCodeMap.PAGE_UP_KEY:
case KeyCodeMap.DOWN_KEY:
case KeyCodeMap.PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
@ -4172,13 +4205,7 @@ var Choices = /** @class */ (function () {
if (!_this._canCreateItem(value)) {
return;
}
var sanitisedValue = sanitise(value);
var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
_this._addChoice(mapInputToChoice({
value: userValue,
label: userValue,
selected: true,
}, false), true, true);
_this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true);
addedItem = true;
}
_this.clearInput();
@ -4196,6 +4223,7 @@ var Choices = /** @class */ (function () {
if (hasActiveDropdown) {
event.stopPropagation();
this.hideDropdown(true);
this._stopSearch();
this.containerOuter.element.focus();
}
};
@ -4205,8 +4233,8 @@ var Choices = /** @class */ (function () {
if (hasActiveDropdown || this._isSelectOneElement) {
this.showDropdown();
this._canSearch = false;
var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1;
var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */;
var directionInt = keyCode === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1;
var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY;
var nextEl = void 0;
if (skipKey) {
if (directionInt > 0) {
@ -4371,19 +4399,16 @@ var Choices = /** @class */ (function () {
var containerOuter = this.containerOuter;
var blurWasWithinContainer = target && containerOuter.element.contains(target);
if (blurWasWithinContainer && !this._isScrollingOnIe) {
var targetIsInput = target === this.input.element;
if (this._isTextElement || this._isSelectMultipleElement) {
if (targetIsInput) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (target === this.input.element) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (this._isTextElement || this._isSelectMultipleElement) {
this.unhighlightAll();
}
}
else {
else if (target === this.containerOuter.element) {
// Remove the focus state when the past outerContainer was the target
containerOuter.removeFocusState();
if (targetIsInput || (target === containerOuter.element && !this._canSearch)) {
this.hideDropdown(true);
}
}
}
else {
@ -4470,6 +4495,10 @@ var Choices = /** @class */ (function () {
return;
}
this._store.dispatch(removeItem$1(item));
var notice = this._notice;
if (notice && notice.type === NoticeTypes.noChoices) {
this._clearNotice();
}
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
};
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
@ -4686,7 +4715,7 @@ var Choices = /** @class */ (function () {
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
}
};
Choices.version = '11.0.2';
Choices.version = '11.0.3';
return Choices;
}());

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.2 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v11.0.3 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@ -80,6 +80,20 @@
unhighlightItem: 'unhighlightItem',
};
var KeyCodeMap = {
TAB_KEY: 9,
SHIFT_KEY: 16,
BACK_KEY: 46,
DELETE_KEY: 8,
ENTER_KEY: 13,
A_KEY: 65,
ESC_KEY: 27,
UP_KEY: 38,
DOWN_KEY: 40,
PAGE_UP_KEY: 33,
PAGE_DOWN_KEY: 34,
};
var ObjectsInConfig = ['fuseOptions', 'classNames'];
var PassedElementTypes = {
@ -736,11 +750,15 @@
}
return undefined;
};
var mapInputToChoice = function (value, allowGroup) {
var mapInputToChoice = function (value, allowGroup, allowRawString) {
if (allowRawString === void 0) { allowRawString = true; }
if (typeof value === 'string') {
var sanitisedValue = sanitise(value);
var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
var result_1 = mapInputToChoice({
value: value,
label: value,
label: userValue,
selected: true,
}, false);
return result_1;
}
@ -845,7 +863,7 @@
score: 0,
rank: 0,
value: option.value,
label: option.innerHTML,
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
element: option,
active: true,
// this returns true if nothing is selected on initial load, which will break placeholder support
@ -1973,11 +1991,15 @@
if (this.dropdown.isActive) {
return this;
}
if (preventInputFocus === undefined) {
// eslint-disable-next-line no-param-reassign
preventInputFocus = !this._canSearch;
}
requestAnimationFrame(function () {
_this.dropdown.show();
var rect = _this.dropdown.element.getBoundingClientRect();
_this.containerOuter.open(rect.bottom, rect.height);
if (!preventInputFocus && _this._canSearch) {
if (!preventInputFocus) {
_this.input.focus();
}
_this.passedElement.triggerEvent(EventType.showDropdown);
@ -2279,6 +2301,7 @@
}
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
@ -2660,6 +2683,7 @@
};
Choices.prototype._loadChoices = function () {
var _a;
var _this = this;
var config = this.config;
if (this._isTextElement) {
// Assign preset items from passed object first
@ -2668,7 +2692,7 @@
if (this.passedElement.value) {
var elementItems = this.passedElement.value
.split(config.delimiter)
.map(function (e) { return mapInputToChoice(e, false); });
.map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); });
this._presetChoices = this._presetChoices.concat(elementItems);
}
this._presetChoices.forEach(function (choice) {
@ -2734,6 +2758,7 @@
var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText;
if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) {
this.choiceList.element.replaceChildren('');
this._notice = undefined;
this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice);
return false;
}
@ -2911,7 +2936,15 @@
var wasPrintableChar = event.key.length === 1 ||
(event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) ||
event.key === 'Unidentified';
if (!this._isTextElement && !hasActiveDropdown) {
/*
We do not show the dropdown if focusing out with esc or navigating through input fields.
An activated search can still be opened with any other key.
*/
if (!this._isTextElement &&
!hasActiveDropdown &&
keyCode !== KeyCodeMap.ESC_KEY &&
keyCode !== KeyCodeMap.TAB_KEY &&
keyCode !== KeyCodeMap.SHIFT_KEY) {
this.showDropdown();
if (!this.input.isFocussed && wasPrintableChar) {
/*
@ -2927,19 +2960,19 @@
}
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
case KeyCodeMap.ESC_KEY:
return this._onEscapeKey(event, hasActiveDropdown);
case 38 /* KeyCodeMap.UP_KEY */:
case 33 /* KeyCodeMap.PAGE_UP_KEY */:
case 40 /* KeyCodeMap.DOWN_KEY */:
case 34 /* KeyCodeMap.PAGE_DOWN_KEY */:
case KeyCodeMap.UP_KEY:
case KeyCodeMap.PAGE_UP_KEY:
case KeyCodeMap.DOWN_KEY:
case KeyCodeMap.PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
@ -3020,13 +3053,7 @@
if (!_this._canCreateItem(value)) {
return;
}
var sanitisedValue = sanitise(value);
var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
_this._addChoice(mapInputToChoice({
value: userValue,
label: userValue,
selected: true,
}, false), true, true);
_this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true);
addedItem = true;
}
_this.clearInput();
@ -3044,6 +3071,7 @@
if (hasActiveDropdown) {
event.stopPropagation();
this.hideDropdown(true);
this._stopSearch();
this.containerOuter.element.focus();
}
};
@ -3053,8 +3081,8 @@
if (hasActiveDropdown || this._isSelectOneElement) {
this.showDropdown();
this._canSearch = false;
var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1;
var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */;
var directionInt = keyCode === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1;
var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY;
var nextEl = void 0;
if (skipKey) {
if (directionInt > 0) {
@ -3219,19 +3247,16 @@
var containerOuter = this.containerOuter;
var blurWasWithinContainer = target && containerOuter.element.contains(target);
if (blurWasWithinContainer && !this._isScrollingOnIe) {
var targetIsInput = target === this.input.element;
if (this._isTextElement || this._isSelectMultipleElement) {
if (targetIsInput) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (target === this.input.element) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (this._isTextElement || this._isSelectMultipleElement) {
this.unhighlightAll();
}
}
else {
else if (target === this.containerOuter.element) {
// Remove the focus state when the past outerContainer was the target
containerOuter.removeFocusState();
if (targetIsInput || (target === containerOuter.element && !this._canSearch)) {
this.hideDropdown(true);
}
}
}
else {
@ -3318,6 +3343,10 @@
return;
}
this._store.dispatch(removeItem$1(item));
var notice = this._notice;
if (notice && notice.type === NoticeTypes.noChoices) {
this._clearNotice();
}
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
};
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
@ -3534,7 +3563,7 @@
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
}
};
Choices.version = '11.0.2';
Choices.version = '11.0.3';
return Choices;
}());

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
/*! choices.js v11.0.2 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v11.0.3 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/******************************************************************************
Copyright (c) Microsoft Corporation.
@ -74,6 +74,20 @@ var EventType = {
unhighlightItem: 'unhighlightItem',
};
var KeyCodeMap = {
TAB_KEY: 9,
SHIFT_KEY: 16,
BACK_KEY: 46,
DELETE_KEY: 8,
ENTER_KEY: 13,
A_KEY: 65,
ESC_KEY: 27,
UP_KEY: 38,
DOWN_KEY: 40,
PAGE_UP_KEY: 33,
PAGE_DOWN_KEY: 34,
};
var ObjectsInConfig = ['fuseOptions', 'classNames'];
var PassedElementTypes = {
@ -730,11 +744,15 @@ var stringToHtmlClass = function (input) {
}
return undefined;
};
var mapInputToChoice = function (value, allowGroup) {
var mapInputToChoice = function (value, allowGroup, allowRawString) {
if (allowRawString === void 0) { allowRawString = true; }
if (typeof value === 'string') {
var sanitisedValue = sanitise(value);
var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
var result_1 = mapInputToChoice({
value: value,
label: value,
label: userValue,
selected: true,
}, false);
return result_1;
}
@ -839,7 +857,7 @@ var WrappedSelect = /** @class */ (function (_super) {
score: 0,
rank: 0,
value: option.value,
label: option.innerHTML,
label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments...
element: option,
active: true,
// this returns true if nothing is selected on initial load, which will break placeholder support
@ -1967,11 +1985,15 @@ var Choices = /** @class */ (function () {
if (this.dropdown.isActive) {
return this;
}
if (preventInputFocus === undefined) {
// eslint-disable-next-line no-param-reassign
preventInputFocus = !this._canSearch;
}
requestAnimationFrame(function () {
_this.dropdown.show();
var rect = _this.dropdown.element.getBoundingClientRect();
_this.containerOuter.open(rect.bottom, rect.height);
if (!preventInputFocus && _this._canSearch) {
if (!preventInputFocus) {
_this.input.focus();
}
_this.passedElement.triggerEvent(EventType.showDropdown);
@ -2273,6 +2295,7 @@ var Choices = /** @class */ (function () {
}
this.itemList.element.replaceChildren('');
this.choiceList.element.replaceChildren('');
this._clearNotice();
this._store.reset();
this._lastAddedChoiceId = 0;
this._lastAddedGroupId = 0;
@ -2654,6 +2677,7 @@ var Choices = /** @class */ (function () {
};
Choices.prototype._loadChoices = function () {
var _a;
var _this = this;
var config = this.config;
if (this._isTextElement) {
// Assign preset items from passed object first
@ -2662,7 +2686,7 @@ var Choices = /** @class */ (function () {
if (this.passedElement.value) {
var elementItems = this.passedElement.value
.split(config.delimiter)
.map(function (e) { return mapInputToChoice(e, false); });
.map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); });
this._presetChoices = this._presetChoices.concat(elementItems);
}
this._presetChoices.forEach(function (choice) {
@ -2728,6 +2752,7 @@ var Choices = /** @class */ (function () {
var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText;
if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) {
this.choiceList.element.replaceChildren('');
this._notice = undefined;
this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice);
return false;
}
@ -2905,7 +2930,15 @@ var Choices = /** @class */ (function () {
var wasPrintableChar = event.key.length === 1 ||
(event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) ||
event.key === 'Unidentified';
if (!this._isTextElement && !hasActiveDropdown) {
/*
We do not show the dropdown if focusing out with esc or navigating through input fields.
An activated search can still be opened with any other key.
*/
if (!this._isTextElement &&
!hasActiveDropdown &&
keyCode !== KeyCodeMap.ESC_KEY &&
keyCode !== KeyCodeMap.TAB_KEY &&
keyCode !== KeyCodeMap.SHIFT_KEY) {
this.showDropdown();
if (!this.input.isFocussed && wasPrintableChar) {
/*
@ -2921,19 +2954,19 @@ var Choices = /** @class */ (function () {
}
}
switch (keyCode) {
case 65 /* KeyCodeMap.A_KEY */:
case KeyCodeMap.A_KEY:
return this._onSelectKey(event, this.itemList.element.hasChildNodes());
case 13 /* KeyCodeMap.ENTER_KEY */:
case KeyCodeMap.ENTER_KEY:
return this._onEnterKey(event, hasActiveDropdown);
case 27 /* KeyCodeMap.ESC_KEY */:
case KeyCodeMap.ESC_KEY:
return this._onEscapeKey(event, hasActiveDropdown);
case 38 /* KeyCodeMap.UP_KEY */:
case 33 /* KeyCodeMap.PAGE_UP_KEY */:
case 40 /* KeyCodeMap.DOWN_KEY */:
case 34 /* KeyCodeMap.PAGE_DOWN_KEY */:
case KeyCodeMap.UP_KEY:
case KeyCodeMap.PAGE_UP_KEY:
case KeyCodeMap.DOWN_KEY:
case KeyCodeMap.PAGE_DOWN_KEY:
return this._onDirectionKey(event, hasActiveDropdown);
case 8 /* KeyCodeMap.DELETE_KEY */:
case 46 /* KeyCodeMap.BACK_KEY */:
case KeyCodeMap.DELETE_KEY:
case KeyCodeMap.BACK_KEY:
return this._onDeleteKey(event, this._store.items, this.input.isFocussed);
}
};
@ -3014,13 +3047,7 @@ var Choices = /** @class */ (function () {
if (!_this._canCreateItem(value)) {
return;
}
var sanitisedValue = sanitise(value);
var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value };
_this._addChoice(mapInputToChoice({
value: userValue,
label: userValue,
selected: true,
}, false), true, true);
_this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true);
addedItem = true;
}
_this.clearInput();
@ -3038,6 +3065,7 @@ var Choices = /** @class */ (function () {
if (hasActiveDropdown) {
event.stopPropagation();
this.hideDropdown(true);
this._stopSearch();
this.containerOuter.element.focus();
}
};
@ -3047,8 +3075,8 @@ var Choices = /** @class */ (function () {
if (hasActiveDropdown || this._isSelectOneElement) {
this.showDropdown();
this._canSearch = false;
var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1;
var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */;
var directionInt = keyCode === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1;
var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY;
var nextEl = void 0;
if (skipKey) {
if (directionInt > 0) {
@ -3213,19 +3241,16 @@ var Choices = /** @class */ (function () {
var containerOuter = this.containerOuter;
var blurWasWithinContainer = target && containerOuter.element.contains(target);
if (blurWasWithinContainer && !this._isScrollingOnIe) {
var targetIsInput = target === this.input.element;
if (this._isTextElement || this._isSelectMultipleElement) {
if (targetIsInput) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (target === this.input.element) {
containerOuter.removeFocusState();
this.hideDropdown(true);
if (this._isTextElement || this._isSelectMultipleElement) {
this.unhighlightAll();
}
}
else {
else if (target === this.containerOuter.element) {
// Remove the focus state when the past outerContainer was the target
containerOuter.removeFocusState();
if (targetIsInput || (target === containerOuter.element && !this._canSearch)) {
this.hideDropdown(true);
}
}
}
else {
@ -3312,6 +3337,10 @@ var Choices = /** @class */ (function () {
return;
}
this._store.dispatch(removeItem$1(item));
var notice = this._notice;
if (notice && notice.type === NoticeTypes.noChoices) {
this._clearNotice();
}
this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item));
};
Choices.prototype._addChoice = function (choice, withEvents, userTriggered) {
@ -3528,7 +3557,7 @@ var Choices = /** @class */ (function () {
throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it"));
}
};
Choices.version = '11.0.2';
Choices.version = '11.0.3';
return Choices;
}());

View file

@ -1,11 +1,13 @@
export declare const enum KeyCodeMap {
BACK_KEY = 46,
DELETE_KEY = 8,
ENTER_KEY = 13,
A_KEY = 65,
ESC_KEY = 27,
UP_KEY = 38,
DOWN_KEY = 40,
PAGE_UP_KEY = 33,
PAGE_DOWN_KEY = 34
}
export declare const KeyCodeMap: {
readonly TAB_KEY: 9;
readonly SHIFT_KEY: 16;
readonly BACK_KEY: 46;
readonly DELETE_KEY: 8;
readonly ENTER_KEY: 13;
readonly A_KEY: 65;
readonly ESC_KEY: 27;
readonly UP_KEY: 38;
readonly DOWN_KEY: 40;
readonly PAGE_UP_KEY: 33;
readonly PAGE_DOWN_KEY: 34;
};

View file

@ -5,5 +5,5 @@ import { ChoiceFull } from '../interfaces/choice-full';
type MappedInputTypeToChoiceType<T extends string | InputChoice | InputGroup> = T extends InputGroup ? GroupFull : ChoiceFull;
export declare const coerceBool: (arg: unknown, defaultValue?: boolean) => boolean;
export declare const stringToHtmlClass: (input: string | string[] | undefined) => string[] | undefined;
export declare const mapInputToChoice: <T extends string | InputChoice | InputGroup>(value: T, allowGroup: boolean) => MappedInputTypeToChoiceType<T>;
export declare const mapInputToChoice: <T extends string | InputChoice | InputGroup>(value: T, allowGroup: boolean, allowRawString?: boolean) => MappedInputTypeToChoiceType<T>;
export {};