From 7978a32dbe994bd73e123769f03907f4b59f745d Mon Sep 17 00:00:00 2001 From: Jai Prakash Rai Date: Fri, 14 Mar 2025 19:52:19 +0530 Subject: [PATCH 1/2] allow spacebar key to select options of multi-select --- index.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 7aedae3..26b2b31 100644 --- a/index.js +++ b/index.js @@ -91,9 +91,7 @@ module.exports = class Combobo { }); this.input.addEventListener('focus', () => { - if (this.selected.length) { - this.input.value = this.selected.length >= 2 ? '' : this.config.selectionValue(this.selected); - } + this.input.select(); }); @@ -172,7 +170,7 @@ module.exports = class Combobo { if (focus) { this.input.focus(); } // Set the value back to what it was if (!this.multiselect && this.selected.length) { - this.input.value = this.config.selectionValue(this.selected); + this.input.value = this.selected.map(item => item.innerText).join(', '); } if (selectText) { this.input.select(); } @@ -214,9 +212,20 @@ module.exports = class Combobo { e.preventDefault(); e.stopPropagation(); this.select(); + } } }, { + keys: ['space'], + callback: (e) => { + if (this.isOpen) { + e.preventDefault(); + e.stopPropagation(); + this.select(); + + } + } + },{ keys: ['escape'], callback: (e) => { if (this.isOpen) { @@ -359,9 +368,7 @@ module.exports = class Combobo { } this.freshSelection = true; - this.input.value = this.selected.length - ? this.config.selectionValue(this.selected) - : ''; + this.input.value = this.selected.length ? this.selected.map(item => item.innerText).join(', '): ''; this.cachedInputValue = this.input.value; this.filter(true).clearFilters() From f7bbd31b7e00d12df89b4a4002a138baec801ee3 Mon Sep 17 00:00:00 2001 From: Jai Prakash Rai Date: Fri, 14 Mar 2025 19:56:32 +0530 Subject: [PATCH 2/2] deleted extra white space. --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 26b2b31..e3902ba 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,6 @@ module.exports = class Combobo { }); this.input.addEventListener('focus', () => { - this.input.select(); });