mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-23 07:52:22 +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
|
// If we actually have anything to add to our dropdown
|
||||||
// append it and highlight the first choice
|
// append it and highlight the first choice
|
||||||
this.choiceList.appendChild(choiceListFragment);
|
this.choiceList.appendChild(choiceListFragment);
|
||||||
this._highlightChoice();
|
|
||||||
} else {
|
} else {
|
||||||
const activeItems = this.store.getItemsFilteredByActive();
|
const activeItems = this.store.getItemsFilteredByActive();
|
||||||
const canAddItem = this._canAddItem(activeItems, this.input.value);
|
const canAddItem = this._canAddItem(activeItems, this.input.value);
|
||||||
|
@ -1032,9 +1031,9 @@ class Choices {
|
||||||
|
|
||||||
if (canAddItem.response) {
|
if (canAddItem.response) {
|
||||||
this._addItem(choice.value, choice.label, choice.id, choice.groupId);
|
this._addItem(choice.value, choice.label, choice.id, choice.groupId);
|
||||||
this._triggerChange(choice.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this._triggerChange(choice.value);
|
||||||
|
|
||||||
this.clearInput(this.passedElement);
|
this.clearInput(this.passedElement);
|
||||||
|
|
||||||
|
@ -1357,6 +1356,22 @@ class Choices {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onEnterKey = () => {
|
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 enter key is pressed and the input has a value
|
||||||
if (target.value) {
|
if (target.value) {
|
||||||
const value = this.input.value;
|
const value = this.input.value;
|
||||||
|
|
|
@ -284,7 +284,7 @@ describe('Choices', () => {
|
||||||
this.choices = new Choices(this.input);
|
this.choices = new Choices(this.input);
|
||||||
this.choices.input.focus();
|
this.choices.input.focus();
|
||||||
|
|
||||||
for (var i = 0; i < 2; i++) {
|
for (var i = 0; i < 3; i++) {
|
||||||
// Key down to third choice
|
// Key down to third choice
|
||||||
this.choices._onKeyDown({
|
this.choices._onKeyDown({
|
||||||
target: this.choices.input,
|
target: this.choices.input,
|
||||||
|
@ -317,7 +317,7 @@ describe('Choices', () => {
|
||||||
preventDefault: () => {}
|
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() {
|
it('should trigger add/change event on selection', function() {
|
||||||
|
|
Loading…
Reference in a new issue