Skip to content

Commit cd54ff9

Browse files
committed
refactor(MultiSelect): add missing disabled property, update CSS variables
1 parent 142e04c commit cd54ff9

File tree

3 files changed

+201
-106
lines changed

3 files changed

+201
-106
lines changed

js/src/multi-select.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const CLASS_NAME_LABEL = 'label'
7373

7474
const Default = {
7575
cleaner: true,
76+
disabled: false,
7677
multiple: true,
7778
placeholder: 'Select...',
7879
options: false,
@@ -88,6 +89,7 @@ const Default = {
8889

8990
const DefaultType = {
9091
cleaner: 'boolean',
92+
disabled: 'boolean',
9193
multiple: 'boolean',
9294
placeholder: 'string',
9395
options: '(boolean|array)',
@@ -109,14 +111,13 @@ const DefaultType = {
109111

110112
class MultiSelect extends BaseComponent {
111113
constructor(element, config) {
112-
super(element)
114+
super(element, config)
113115

114116
this._selectAllElement = null
115117
this._selectionElement = null
116118
this._selectionCleanerElement = null
117119
this._searchElement = null
118120
this._optionsElement = null
119-
this._config = this._getConfig(config)
120121
this._clone = null
121122
this._options = this._getOptions()
122123
this._search = ''
@@ -223,7 +224,9 @@ class MultiSelect extends BaseComponent {
223224

224225
_addEventListeners() {
225226
EventHandler.on(this._clone, EVENT_CLICK, () => {
226-
this.show()
227+
if (!this._config.disabled) {
228+
this.show()
229+
}
227230
})
228231

229232
EventHandler.on(this._searchElement, EVENT_KEYUP, () => {
@@ -251,9 +254,11 @@ class MultiSelect extends BaseComponent {
251254
})
252255

253256
EventHandler.on(this._selectionCleanerElement, EVENT_CLICK, event => {
254-
event.preventDefault()
255-
event.stopPropagation()
256-
this.deselectAll()
257+
if (!this._config.disabled) {
258+
event.preventDefault()
259+
event.stopPropagation()
260+
this.deselectAll()
261+
}
257262
})
258263

259264
EventHandler.on(this._optionsElement, EVENT_KEYDOWN, event => {
@@ -378,6 +383,10 @@ class MultiSelect extends BaseComponent {
378383
const div = document.createElement('div')
379384
div.classList.add(CLASS_NAME_SELECT)
380385

386+
if (this._config.disabled) {
387+
this._element.classList.add(CLASS_NAME_DISABLED)
388+
}
389+
381390
for (const className of this._getClassNames()) {
382391
div.classList.add(className)
383392
}
@@ -431,6 +440,10 @@ class MultiSelect extends BaseComponent {
431440
const input = document.createElement('input')
432441
input.classList.add(CLASS_NAME_SEARCH)
433442

443+
if (this._config.disabled) {
444+
input.disabled = true
445+
}
446+
434447
this._searchElement = input
435448
this._updateSearchSize()
436449

@@ -516,11 +529,13 @@ class MultiSelect extends BaseComponent {
516529
tag.append(closeBtn)
517530

518531
EventHandler.on(closeBtn, EVENT_CLICK, event => {
519-
event.preventDefault()
520-
event.stopPropagation()
532+
if (!this._config.disabled) {
533+
event.preventDefault()
534+
event.stopPropagation()
521535

522-
tag.remove()
523-
this._deselectOption(value)
536+
tag.remove()
537+
this._deselectOption(value)
538+
}
524539
})
525540

526541
return tag

scss/_variables.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ $form-multi-select-select-all-color: $medium-emphasis !default;
12401240
$form-multi-select-select-all-bg: transparent !default;
12411241
$form-multi-select-select-all-hover-color: $high-emphasis !default;
12421242
$form-multi-select-select-all-hover-bg: transparent !default;
1243+
$form-multi-select-select-all-border-width: $input-border-width !default;
12431244
$form-multi-select-select-all-border-color: $input-border-color !default;
12441245

12451246
$form-multi-select-options-padding-y: .5rem !default;
@@ -1265,7 +1266,7 @@ $form-multi-select-option-hover-bg: rgba($gray-100, .5) !default;
12651266
$form-multi-select-option-indicator-width: 1em !default;
12661267
$form-multi-select-option-indicator-bg: $form-check-input-bg !default;
12671268
$form-multi-select-option-indicator-border: $form-check-input-border !default;
1268-
$form-multi-select-option-indicator-border-radius: $border-radius !default;
1269+
$form-multi-select-option-indicator-border-radius: .25em !default;
12691270

12701271
$form-multi-select-option-selected-bg: $light !default;
12711272
$form-multi-select-option-selected-indicator-bg: $form-check-input-checked-bg-color !default;

0 commit comments

Comments
 (0)