From 05d8091bd35ba5e2a5f468efce7e37cfab898295 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 19 May 2020 20:39:29 +0200 Subject: [PATCH] DEV: adds triggerOnChangeOnTab option to select-kit (#9833) Usage: ``` options=(hash triggerOnChangeOnTab=false) ``` This will prevent to select the row when pressing tab. --- .../discourse/app/templates/components/d-navigation.hbs | 3 +++ .../javascripts/select-kit/app/components/select-kit.js | 3 ++- .../app/components/select-kit/select-kit-header.js | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs b/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs index e9e0b9a34f1..2ac52d5f71b 100644 --- a/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs @@ -3,6 +3,9 @@ {{#if showCategoryAdmin}} {{categories-admin-dropdown onChange=(action "selectCategoryAdminDropdownAction") + options=(hash + triggerOnChangeOnTab=false + ) }} {{/if}} diff --git a/app/assets/javascripts/select-kit/app/components/select-kit.js b/app/assets/javascripts/select-kit/app/components/select-kit.js index f2fbbbf1c2b..140e96782d6 100644 --- a/app/assets/javascripts/select-kit/app/components/select-kit.js +++ b/app/assets/javascripts/select-kit/app/components/select-kit.js @@ -271,7 +271,8 @@ export default Component.extend( selectedNameComponent: "selected-name", castInteger: false, preventsClickPropagation: false, - focusAfterOnChange: true + focusAfterOnChange: true, + triggerOnChangeOnTab: true }, autoFilterable: computed("content.[]", "selectKit.filter", function() { diff --git a/app/assets/javascripts/select-kit/app/components/select-kit/select-kit-header.js b/app/assets/javascripts/select-kit/app/components/select-kit/select-kit-header.js index 785b2a47022..5697826f59f 100644 --- a/app/assets/javascripts/select-kit/app/components/select-kit/select-kit-header.js +++ b/app/assets/javascripts/select-kit/app/components/select-kit/select-kit-header.js @@ -140,7 +140,11 @@ export default Component.extend(UtilsMixin, { this._focusFilterInput(); } else if (event.keyCode === 9) { // Tab - if (this.selectKit.highlighted && this.selectKit.isExpanded) { + if ( + this.selectKit.highlighted && + this.selectKit.isExpanded && + this.selectKit.options.triggerOnChangeOnTab + ) { this.selectKit.select( this.getValue(this.selectKit.highlighted), this.selectKit.highlighted