mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-14 03:35:31 +02:00
Ensure enter key can also open single select dropdown
This commit is contained in:
parent
da68a92f31
commit
6fadbde79e
|
@ -709,9 +709,18 @@ export class Choices {
|
||||||
this._handleEnter(activeItems, value);
|
this._handleEnter(activeItems, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show dropdown if focus
|
||||||
|
if(!hasActiveDropdown && this.passedElement.type === 'select-one'){
|
||||||
|
e.preventDefault();
|
||||||
|
this.showDropdown();
|
||||||
|
if(this.canSearch) {
|
||||||
|
this.input.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(hasActiveDropdown) {
|
if(hasActiveDropdown) {
|
||||||
const highlighted = this.dropdown.querySelector(`.${this.config.classNames.highlightedState}`);
|
const highlighted = this.dropdown.querySelector(`.${this.config.classNames.highlightedState}`);
|
||||||
|
|
||||||
if(highlighted) {
|
if(highlighted) {
|
||||||
const value = highlighted.getAttribute('data-value');
|
const value = highlighted.getAttribute('data-value');
|
||||||
const label = highlighted.innerHTML;
|
const label = highlighted.innerHTML;
|
||||||
|
@ -1030,6 +1039,7 @@ export class Choices {
|
||||||
if(!this._focusAndHideDropdown){
|
if(!this._focusAndHideDropdown){
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._focusAndHideDropdown = false;
|
this._focusAndHideDropdown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1064,7 +1074,8 @@ export class Choices {
|
||||||
*/
|
*/
|
||||||
_regexFilter(value) {
|
_regexFilter(value) {
|
||||||
if(!value) return;
|
if(!value) return;
|
||||||
const expression = new RegExp(this.config.regexFilter, 'i');
|
const regex = this.config.regexFilter;
|
||||||
|
const expression = new RegExp(regex.source, 'i');
|
||||||
return expression.test(value);
|
return expression.test(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue