mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-12 02:26:35 +02:00
Fix item selection against manual input
This commit is contained in:
parent
217015caef
commit
696026e24e
|
@ -411,7 +411,6 @@ class Choices {
|
|||
// If we actually have anything to add to our dropdown
|
||||
// append it and highlight the first choice
|
||||
this.choiceList.appendChild(choiceListFragment);
|
||||
this._highlightChoice();
|
||||
} else {
|
||||
const activeItems = this.store.getItemsFilteredByActive();
|
||||
const canAddItem = this._canAddItem(activeItems, this.input.value);
|
||||
|
@ -1032,9 +1031,9 @@ class Choices {
|
|||
|
||||
if (canAddItem.response) {
|
||||
this._addItem(choice.value, choice.label, choice.id, choice.groupId);
|
||||
this._triggerChange(choice.value);
|
||||
}
|
||||
}
|
||||
this._triggerChange(choice.value);
|
||||
|
||||
this.clearInput(this.passedElement);
|
||||
|
||||
|
@ -1357,6 +1356,22 @@ class Choices {
|
|||
};
|
||||
|
||||
const onEnterKey = () => {
|
||||
|
||||
if (hasActiveDropdown) {
|
||||
const highlighted = this.dropdown.querySelector(`.${this.config.classNames.highlightedState}`);
|
||||
|
||||
// If we have a highlighted choice
|
||||
if (highlighted) {
|
||||
this._handleChoiceAction(activeItems, highlighted);
|
||||
}
|
||||
} else if (passedElementType === 'select-one') {
|
||||
// Open single select dropdown if it's not active
|
||||
if (!hasActiveDropdown) {
|
||||
this.showDropdown(true);
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
// If enter key is pressed and the input has a value
|
||||
if (target.value) {
|
||||
const value = this.input.value;
|
||||
|
|
|
@ -284,7 +284,7 @@ describe('Choices', () => {
|
|||
this.choices = new Choices(this.input);
|
||||
this.choices.input.focus();
|
||||
|
||||
for (var i = 0; i < 2; i++) {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
// Key down to third choice
|
||||
this.choices._onKeyDown({
|
||||
target: this.choices.input,
|
||||
|
@ -317,7 +317,7 @@ describe('Choices', () => {
|
|||
preventDefault: () => {}
|
||||
});
|
||||
|
||||
expect(this.choices.currentState.items.length).toBe(2);
|
||||
expect(this.choices.currentState.items.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should trigger add/change event on selection', function() {
|
||||
|
|
Loading…
Reference in a new issue