mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 21:16:34 +02:00
Merge 61e48f846a
into 5dbea2825a
This commit is contained in:
commit
dcd8ce7697
10
README.md
10
README.md
|
@ -122,6 +122,7 @@ Or include Choices directly:
|
||||||
choices: [],
|
choices: [],
|
||||||
renderChoiceLimit: -1,
|
renderChoiceLimit: -1,
|
||||||
maxItemCount: -1,
|
maxItemCount: -1,
|
||||||
|
addChoices: false,
|
||||||
addItems: true,
|
addItems: true,
|
||||||
addItemFilter: null,
|
addItemFilter: null,
|
||||||
removeItems: true,
|
removeItems: true,
|
||||||
|
@ -304,6 +305,15 @@ Pass an array of objects:
|
||||||
|
|
||||||
**Usage:** The amount of items a user can input/select ("-1" indicates no limit).
|
**Usage:** The amount of items a user can input/select ("-1" indicates no limit).
|
||||||
|
|
||||||
|
### addChoices
|
||||||
|
**Type**: `Boolean` **Default:** `false`
|
||||||
|
|
||||||
|
**Input types affected:** `select-multiple`, `select-one`
|
||||||
|
|
||||||
|
**Usage:** Whether a user can add choices
|
||||||
|
|
||||||
|
**Note:** `addItems` must also be `true`
|
||||||
|
|
||||||
### addItems
|
### addItems
|
||||||
|
|
||||||
**Type:** `Boolean` **Default:** `true`
|
**Type:** `Boolean` **Default:** `true`
|
||||||
|
|
|
@ -1006,6 +1006,24 @@ describe('Choices - select multiple', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('adding user-created choices', () => {
|
||||||
|
it('allows the user to add choices', () => {
|
||||||
|
const newChoice = 'New Choice';
|
||||||
|
|
||||||
|
cy.get('[data-test-hook=add-choices]')
|
||||||
|
.find('.choices__input--cloned')
|
||||||
|
.type(newChoice)
|
||||||
|
.type('{enter}');
|
||||||
|
|
||||||
|
cy.get('[data-test-hook=add-choices]')
|
||||||
|
.find('.choices__list--multiple')
|
||||||
|
.last()
|
||||||
|
.should($el => {
|
||||||
|
expect($el).to.contain(newChoice);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1145,5 +1145,26 @@ describe('Choices - select one', () => {
|
||||||
.should('have.length', 3);
|
.should('have.length', 3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('adding user-created choices', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.get('[data-test-hook=add-choices]').find('.choices').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows the user to add choices', () => {
|
||||||
|
const newChoice = 'New Choice';
|
||||||
|
|
||||||
|
cy.get('[data-test-hook=add-choices]')
|
||||||
|
.find('.choices__input--cloned')
|
||||||
|
.type(newChoice)
|
||||||
|
.type('{enter}');
|
||||||
|
|
||||||
|
cy.get('[data-test-hook=add-choices]')
|
||||||
|
.find('.choices__list--single .choices__item')
|
||||||
|
.should(($el) => {
|
||||||
|
expect($el).to.contain(newChoice);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*! choices.js v10.2.0 | © 2022 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
|
/*! choices.js v10.2.0 | © 2023 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
|
||||||
(function webpackUniversalModuleDefinition(root, factory) {
|
(function webpackUniversalModuleDefinition(root, factory) {
|
||||||
if(typeof exports === 'object' && typeof module === 'object')
|
if(typeof exports === 'object' && typeof module === 'object')
|
||||||
module.exports = factory();
|
module.exports = factory();
|
||||||
|
@ -807,9 +807,8 @@ var Choices = /** @class */function () {
|
||||||
} else if (activeChoices.length >= 1) {
|
} else if (activeChoices.length >= 1) {
|
||||||
choiceListFragment = this._createChoicesFragment(activeChoices, choiceListFragment);
|
choiceListFragment = this._createChoicesFragment(activeChoices, choiceListFragment);
|
||||||
}
|
}
|
||||||
// If we have choices to show
|
var activeItems = this._store.activeItems; // If we have choices to show
|
||||||
if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) {
|
if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) {
|
||||||
var activeItems = this._store.activeItems;
|
|
||||||
var canAddItem = this._canAddItem(activeItems, this.input.value);
|
var canAddItem = this._canAddItem(activeItems, this.input.value);
|
||||||
// ...and we can select them
|
// ...and we can select them
|
||||||
if (canAddItem.response) {
|
if (canAddItem.response) {
|
||||||
|
@ -822,13 +821,15 @@ var Choices = /** @class */function () {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise show a notice
|
// Otherwise show a notice
|
||||||
|
var canAddChoice = this._canAddChoice(activeItems, this.input.value);
|
||||||
var dropdownItem = void 0;
|
var dropdownItem = void 0;
|
||||||
var notice = void 0;
|
if (canAddChoice.response) {
|
||||||
if (this._isSearching) {
|
dropdownItem = this._getTemplate('notice', canAddChoice.notice);
|
||||||
notice = typeof this.config.noResultsText === 'function' ? this.config.noResultsText() : this.config.noResultsText;
|
} else if (this._isSearching) {
|
||||||
|
var notice = typeof this.config.noResultsText === 'function' ? this.config.noResultsText() : this.config.noResultsText;
|
||||||
dropdownItem = this._getTemplate('notice', notice, 'no-results');
|
dropdownItem = this._getTemplate('notice', notice, 'no-results');
|
||||||
} else {
|
} else {
|
||||||
notice = typeof this.config.noChoicesText === 'function' ? this.config.noChoicesText() : this.config.noChoicesText;
|
var notice = typeof this.config.noChoicesText === 'function' ? this.config.noChoicesText() : this.config.noChoicesText;
|
||||||
dropdownItem = this._getTemplate('notice', notice, 'no-choices');
|
dropdownItem = this._getTemplate('notice', notice, 'no-choices');
|
||||||
}
|
}
|
||||||
this.choiceList.append(dropdownItem);
|
this.choiceList.append(dropdownItem);
|
||||||
|
@ -1151,6 +1152,11 @@ var Choices = /** @class */function () {
|
||||||
this._store.dispatch((0, choices_1.activateChoices)(true));
|
this._store.dispatch((0, choices_1.activateChoices)(true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Choices.prototype._canAddChoice = function (activeItems, value) {
|
||||||
|
var canAddItem = this._canAddItem(activeItems, value);
|
||||||
|
canAddItem.response = this.config.addChoices && canAddItem.response;
|
||||||
|
return canAddItem;
|
||||||
|
};
|
||||||
Choices.prototype._canAddItem = function (activeItems, value) {
|
Choices.prototype._canAddItem = function (activeItems, value) {
|
||||||
var canAddItem = true;
|
var canAddItem = true;
|
||||||
var notice = typeof this.config.addItemText === 'function' ? this.config.addItemText(value) : this.config.addItemText;
|
var notice = typeof this.config.addItemText === 'function' ? this.config.addItemText(value) : this.config.addItemText;
|
||||||
|
@ -1354,16 +1360,19 @@ var Choices = /** @class */function () {
|
||||||
var target = event.target;
|
var target = event.target;
|
||||||
var enterKey = constants_1.KEY_CODES.ENTER_KEY;
|
var enterKey = constants_1.KEY_CODES.ENTER_KEY;
|
||||||
var targetWasButton = target && target.hasAttribute('data-button');
|
var targetWasButton = target && target.hasAttribute('data-button');
|
||||||
if (this._isTextElement && target && target.value) {
|
var addedItem = false;
|
||||||
|
if (target && target.value) {
|
||||||
var value = this.input.value;
|
var value = this.input.value;
|
||||||
var canAddItem = this._canAddItem(activeItems, value);
|
var canAddItem = this._canAddItem(activeItems, value);
|
||||||
if (canAddItem.response) {
|
var canAddChoice = this._canAddChoice(activeItems, value);
|
||||||
|
if (this._isTextElement && canAddItem.response || !this._isTextElement && canAddChoice.response) {
|
||||||
this.hideDropdown(true);
|
this.hideDropdown(true);
|
||||||
this._addItem({
|
this._addItem({
|
||||||
value: value
|
value: value
|
||||||
});
|
});
|
||||||
this._triggerChange(value);
|
this._triggerChange(value);
|
||||||
this.clearInput();
|
this.clearInput();
|
||||||
|
addedItem = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (targetWasButton) {
|
if (targetWasButton) {
|
||||||
|
@ -1373,12 +1382,16 @@ var Choices = /** @class */function () {
|
||||||
if (hasActiveDropdown) {
|
if (hasActiveDropdown) {
|
||||||
var highlightedChoice = this.dropdown.getChild(".".concat(this.config.classNames.highlightedState));
|
var highlightedChoice = this.dropdown.getChild(".".concat(this.config.classNames.highlightedState));
|
||||||
if (highlightedChoice) {
|
if (highlightedChoice) {
|
||||||
// add enter keyCode value
|
if (addedItem) {
|
||||||
if (activeItems[0]) {
|
this.unhighlightAll();
|
||||||
activeItems[0].keyCode = enterKey; // eslint-disable-line no-param-reassign
|
} else {
|
||||||
}
|
if (activeItems[0]) {
|
||||||
|
// add enter keyCode value
|
||||||
|
activeItems[0].keyCode = enterKey; // eslint-disable-line no-param-reassign
|
||||||
|
}
|
||||||
|
|
||||||
this._handleChoiceAction(activeItems, highlightedChoice);
|
this._handleChoiceAction(activeItems, highlightedChoice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (this._isSelectOneElement) {
|
} else if (this._isSelectOneElement) {
|
||||||
|
@ -2874,6 +2887,7 @@ exports.DEFAULT_CONFIG = {
|
||||||
silent: false,
|
silent: false,
|
||||||
renderChoiceLimit: -1,
|
renderChoiceLimit: -1,
|
||||||
maxItemCount: -1,
|
maxItemCount: -1,
|
||||||
|
addChoices: false,
|
||||||
addItems: true,
|
addItems: true,
|
||||||
addItemFilter: null,
|
addItemFilter: null,
|
||||||
removeItems: true,
|
removeItems: true,
|
||||||
|
@ -4168,7 +4182,7 @@ function getMergeFunction(key, options) {
|
||||||
function getEnumerableOwnPropertySymbols(target) {
|
function getEnumerableOwnPropertySymbols(target) {
|
||||||
return Object.getOwnPropertySymbols
|
return Object.getOwnPropertySymbols
|
||||||
? Object.getOwnPropertySymbols(target).filter(function(symbol) {
|
? Object.getOwnPropertySymbols(target).filter(function(symbol) {
|
||||||
return target.propertyIsEnumerable(symbol)
|
return Object.propertyIsEnumerable.call(target, symbol)
|
||||||
})
|
})
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
@ -6816,15 +6830,6 @@ function applyMiddleware() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* This is a dummy function to check if the function name has been altered by minification.
|
|
||||||
* If the function has been minified and NODE_ENV !== 'production', warn the user.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function isCrushed() {}
|
|
||||||
|
|
||||||
if (false) {}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
2
public/assets/scripts/choices.min.js
vendored
2
public/assets/scripts/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
/*! choices.js v10.2.0 | © 2022 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
|
/*! choices.js v10.2.0 | © 2023 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
|
||||||
|
|
|
@ -397,6 +397,15 @@
|
||||||
multiple
|
multiple
|
||||||
></select>
|
></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div data-test-hook="add-choices">
|
||||||
|
<label for="choices-add-choices">Add choices</label>
|
||||||
|
<select class="form-control" name="choices-add-choices" id="choices-add-choices" multiple>
|
||||||
|
<option value="Choice 1">Choice 1</option>
|
||||||
|
<option value="Choice 2">Choice 2</option>
|
||||||
|
<option value="Choice 3">Choice 3</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
@ -622,6 +631,8 @@
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Choices('#choices-add-choices', { addChoices: true });
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -417,6 +417,16 @@
|
||||||
<button class="destroy">Destroy</button>
|
<button class="destroy">Destroy</button>
|
||||||
<button class="init">Init</button>
|
<button class="init">Init</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div data-test-hook="add-choices">
|
||||||
|
<label for="choices-add-choices">Add choices</label>
|
||||||
|
<select class="form-control" name="choices-add-choices" id="choices-add-choices">
|
||||||
|
<option value="Choice 1">Choice 1</option>
|
||||||
|
<option value="Choice 2">Choice 2</option>
|
||||||
|
<option value="Choice 3">Choice 3</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
@ -676,6 +686,8 @@
|
||||||
document.querySelector('button.init').addEventListener('click', () => {
|
document.querySelector('button.init').addEventListener('click', () => {
|
||||||
newDestroyInitChoices.init();
|
newDestroyInitChoices.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
new Choices('#choices-add-choices', { addChoices: true });
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
1
public/types/src/scripts/choices.d.ts
vendored
1
public/types/src/scripts/choices.d.ts
vendored
|
@ -150,6 +150,7 @@ declare class Choices implements Choices {
|
||||||
_stopLoading(): void;
|
_stopLoading(): void;
|
||||||
_handleLoadingState(setLoading?: boolean): void;
|
_handleLoadingState(setLoading?: boolean): void;
|
||||||
_handleSearch(value: string): void;
|
_handleSearch(value: string): void;
|
||||||
|
_canAddChoice(activeItems: Item[], value: string): Notice;
|
||||||
_canAddItem(activeItems: Item[], value: string): Notice;
|
_canAddItem(activeItems: Item[], value: string): Notice;
|
||||||
_searchChoices(value: string): number;
|
_searchChoices(value: string): number;
|
||||||
_addEventListeners(): void;
|
_addEventListeners(): void;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/scripts/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,eAAO,MAAM,kBAAkB,EAAE,UA2BhC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OA+C5B,CAAC"}
|
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/scripts/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,eAAO,MAAM,kBAAkB,EAAE,UA2BhC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAgD5B,CAAC"}
|
|
@ -96,6 +96,14 @@ export interface Options {
|
||||||
* @default -1
|
* @default -1
|
||||||
*/
|
*/
|
||||||
maxItemCount: number;
|
maxItemCount: number;
|
||||||
|
/**
|
||||||
|
* Whether a user can add choices dynamically.
|
||||||
|
*
|
||||||
|
* **Input types affected:** select-one, select-multiple
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
addChoices: boolean;
|
||||||
/**
|
/**
|
||||||
* Whether a user can add items.
|
* Whether a user can add items.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/interfaces/options.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;OAMG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IA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CAAC,cAAc,CAAC;IAE7C;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC;IAE7C;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;OASG;IACH,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,mBAAmB,CAAC;IAEhD;;;;OAIG;IACH,cAAc,EAAE,MAAM,GAAG,KAAK,CAAC,oBAAoB,CAAC;IAEpD;;;;;;OAMG;IACH,iBAAiB,EAAE,MAAM,GAAG,KAAK,CAAC,oBAAoB,CAAC;IAEvD;;;;;;;;;OASG;IACH,aAAa,EAAE,KAAK,CAAC,oBAAoB,CAAC;IAE1C;;;;OAIG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAExC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,yBAAyB,EAAE,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CACvE"}
|
|
@ -825,12 +825,12 @@ class Choices implements Choices {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have choices to show
|
const { activeItems } = this._store; // If we have choices to show
|
||||||
|
|
||||||
if (
|
if (
|
||||||
choiceListFragment.childNodes &&
|
choiceListFragment.childNodes &&
|
||||||
choiceListFragment.childNodes.length > 0
|
choiceListFragment.childNodes.length > 0
|
||||||
) {
|
) {
|
||||||
const { activeItems } = this._store;
|
|
||||||
const canAddItem = this._canAddItem(activeItems, this.input.value);
|
const canAddItem = this._canAddItem(activeItems, this.input.value);
|
||||||
|
|
||||||
// ...and we can select them
|
// ...and we can select them
|
||||||
|
@ -844,18 +844,21 @@ class Choices implements Choices {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise show a notice
|
// Otherwise show a notice
|
||||||
let dropdownItem;
|
const canAddChoice = this._canAddChoice(activeItems, this.input.value);
|
||||||
let notice;
|
|
||||||
|
|
||||||
if (this._isSearching) {
|
let dropdownItem;
|
||||||
notice =
|
|
||||||
|
if (canAddChoice.response) {
|
||||||
|
dropdownItem = this._getTemplate('notice', canAddChoice.notice);
|
||||||
|
} else if (this._isSearching) {
|
||||||
|
const notice =
|
||||||
typeof this.config.noResultsText === 'function'
|
typeof this.config.noResultsText === 'function'
|
||||||
? this.config.noResultsText()
|
? this.config.noResultsText()
|
||||||
: this.config.noResultsText;
|
: this.config.noResultsText;
|
||||||
|
|
||||||
dropdownItem = this._getTemplate('notice', notice, 'no-results');
|
dropdownItem = this._getTemplate('notice', notice, 'no-results');
|
||||||
} else {
|
} else {
|
||||||
notice =
|
const notice =
|
||||||
typeof this.config.noChoicesText === 'function'
|
typeof this.config.noChoicesText === 'function'
|
||||||
? this.config.noChoicesText()
|
? this.config.noChoicesText()
|
||||||
: this.config.noChoicesText;
|
: this.config.noChoicesText;
|
||||||
|
@ -1260,6 +1263,14 @@ class Choices implements Choices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_canAddChoice(activeItems: Item[], value: string): Notice {
|
||||||
|
const canAddItem = this._canAddItem(activeItems, value);
|
||||||
|
|
||||||
|
canAddItem.response = this.config.addChoices && canAddItem.response;
|
||||||
|
|
||||||
|
return canAddItem;
|
||||||
|
}
|
||||||
|
|
||||||
_canAddItem(activeItems: Item[], value: string): Notice {
|
_canAddItem(activeItems: Item[], value: string): Notice {
|
||||||
let canAddItem = true;
|
let canAddItem = true;
|
||||||
let notice =
|
let notice =
|
||||||
|
@ -1555,16 +1566,22 @@ class Choices implements Choices {
|
||||||
const { ENTER_KEY: enterKey } = KEY_CODES;
|
const { ENTER_KEY: enterKey } = KEY_CODES;
|
||||||
const targetWasButton =
|
const targetWasButton =
|
||||||
target && (target as HTMLElement).hasAttribute('data-button');
|
target && (target as HTMLElement).hasAttribute('data-button');
|
||||||
|
let addedItem = false;
|
||||||
|
|
||||||
if (this._isTextElement && target && (target as HTMLInputElement).value) {
|
if (target && (target as HTMLInputElement).value) {
|
||||||
const { value } = this.input;
|
const { value } = this.input;
|
||||||
const canAddItem = this._canAddItem(activeItems, value);
|
const canAddItem = this._canAddItem(activeItems, value);
|
||||||
|
const canAddChoice = this._canAddChoice(activeItems, value);
|
||||||
|
|
||||||
if (canAddItem.response) {
|
if (
|
||||||
|
(this._isTextElement && canAddItem.response) ||
|
||||||
|
(!this._isTextElement && canAddChoice.response)
|
||||||
|
) {
|
||||||
this.hideDropdown(true);
|
this.hideDropdown(true);
|
||||||
this._addItem({ value });
|
this._addItem({ value });
|
||||||
this._triggerChange(value);
|
this._triggerChange(value);
|
||||||
this.clearInput();
|
this.clearInput();
|
||||||
|
addedItem = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1579,11 +1596,15 @@ class Choices implements Choices {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (highlightedChoice) {
|
if (highlightedChoice) {
|
||||||
// add enter keyCode value
|
if (addedItem) {
|
||||||
if (activeItems[0]) {
|
this.unhighlightAll();
|
||||||
activeItems[0].keyCode = enterKey; // eslint-disable-line no-param-reassign
|
} else {
|
||||||
|
if (activeItems[0]) {
|
||||||
|
// add enter keyCode value
|
||||||
|
activeItems[0].keyCode = enterKey; // eslint-disable-line no-param-reassign
|
||||||
|
}
|
||||||
|
this._handleChoiceAction(activeItems, highlightedChoice);
|
||||||
}
|
}
|
||||||
this._handleChoiceAction(activeItems, highlightedChoice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
@ -37,6 +37,7 @@ export const DEFAULT_CONFIG: Options = {
|
||||||
silent: false,
|
silent: false,
|
||||||
renderChoiceLimit: -1,
|
renderChoiceLimit: -1,
|
||||||
maxItemCount: -1,
|
maxItemCount: -1,
|
||||||
|
addChoices: false,
|
||||||
addItems: true,
|
addItems: true,
|
||||||
addItemFilter: null,
|
addItemFilter: null,
|
||||||
removeItems: true,
|
removeItems: true,
|
||||||
|
|
|
@ -102,6 +102,15 @@ export interface Options {
|
||||||
*/
|
*/
|
||||||
maxItemCount: number;
|
maxItemCount: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a user can add choices dynamically.
|
||||||
|
*
|
||||||
|
* **Input types affected:** select-one, select-multiple
|
||||||
|
*
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
addChoices: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether a user can add items.
|
* Whether a user can add items.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue