From 6fadbde79e1a5e29a5e60eb420ed5af430fcb38b Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Tue, 2 Aug 2016 13:48:17 +0100 Subject: [PATCH] Ensure enter key can also open single select dropdown --- assets/scripts/src/choices.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 331089c..a470163 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -709,9 +709,18 @@ export class Choices { 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) { const highlighted = this.dropdown.querySelector(`.${this.config.classNames.highlightedState}`); - + if(highlighted) { const value = highlighted.getAttribute('data-value'); const label = highlighted.innerHTML; @@ -1030,6 +1039,7 @@ export class Choices { if(!this._focusAndHideDropdown){ this.input.focus(); } + this._focusAndHideDropdown = false; } } @@ -1064,7 +1074,8 @@ export class Choices { */ _regexFilter(value) { 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); }