Skip to content

Commit 8868b1f

Browse files
Merge pull request #74 from abhimediratta:feature/disabled-state
Add disabled and readonly state
2 parents cac8c83 + a3f007f commit 8868b1f

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

src/components/MultiSelect/MultiSelect.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div class="msl-multi-select">
33
<SearchableList
4+
v-if="!readOnly"
45
:list-items="availableOptions"
56
:no-options-text="noOptionsText"
67
:no-items-found-text="noOptionsFoundText"
@@ -15,12 +16,13 @@
1516
:highlight-diff="highlightDiff"
1617
:hide-search-input="hideSearchInputs"
1718
@onClickOption="onOptionSelect"
19+
:disabled="disabled"
1820
/>
1921

20-
<div class="msl-multi-select__actions">
22+
<div class="msl-multi-select__actions" v-if="!readOnly">
2123
<a
2224
class="msl-multi-select__action msl-multi-select__action-select-all"
23-
:class="{'invisible': !showSelectAllButtons}"
25+
:class="{'invisible': !showSelectAllButtons, 'msl-multi-select__action--disabled': disabled }"
2426
@click="onSelectAllOptions"
2527
>
2628
<font-awesome-icon icon="angle-double-right" />
@@ -30,7 +32,7 @@
3032

3133
<a
3234
class="msl-multi-select__action msl-multi-select__action-unselect-all"
33-
:class="{'invisible': !showSelectAllButtons}"
35+
:class="{'invisible': !showSelectAllButtons, 'msl-multi-select__action--disabled': disabled}"
3436
@click="onUnselectAllOptions"
3537
>
3638
<font-awesome-icon icon="angle-double-left" />
@@ -51,6 +53,8 @@
5153
:hide-search-input="hideSearchInputs"
5254
class="msl-multi-select__selected msl-multi-select__list"
5355
@onClickOption="onOptionRemove"
56+
:disabled="disabled"
57+
:read-only="readOnly"
5458
/>
5559
</div>
5660
</template>
@@ -201,6 +205,14 @@ export default {
201205
type: Boolean,
202206
default: false,
203207
},
208+
disabled: {
209+
type: Boolean,
210+
default: false,
211+
},
212+
readOnly: {
213+
type: Boolean,
214+
default: false,
215+
},
204216
},
205217
206218
data() {
@@ -296,6 +308,10 @@ export default {
296308
},
297309
298310
onSelectAllOptions() {
311+
if (this.disabled || this.readOnly) {
312+
return;
313+
}
314+
299315
this.selectedItems = [...this.options];
300316
301317
const selectedValues = getValuesFromOptions(this.reduceValueProperty, this.options);
@@ -309,6 +325,10 @@ export default {
309325
},
310326
311327
onUnselectAllOptions() {
328+
if (this.disabled || this.readOnly) {
329+
return;
330+
}
331+
312332
this.addToNewlyRemovedItems(this.selectedItems);
313333
this.addToNewlyAddedItems([], true);
314334

src/components/SearchableList/SearchableList.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
:class="searchInputClass"
88
:placeholder="placeholderText"
99
>
10-
<div class="msl-searchable-list__items">
10+
<div class="msl-searchable-list__items"
11+
:class="{ 'msl-searchable-list__items--disabled': disabled || readOnly }">
1112
<div
1213
v-for="(option, index) in filteredListItems"
1314
:key="index"
1415
class="msl-searchable-list__item"
15-
:class="{'msl-searchable-list__item--disabled': option.disabled, [highlightClass]: highlightDiff && highlightedItemsMap[getValue(option)] }"
16+
:class="{'msl-searchable-list__item--disabled': option.disabled || disabled || readOnly, [highlightClass]: highlightDiff && highlightedItemsMap[getValue(option)] }"
1617
@click="clickOption(option)"
1718
>
1819
{{ getOptionDisplay(option) }}
@@ -109,6 +110,14 @@ export default {
109110
type: Boolean,
110111
default: false,
111112
},
113+
disabled: {
114+
type: Boolean,
115+
default: false,
116+
},
117+
readOnly: {
118+
type: Boolean,
119+
default: false,
120+
},
112121
},
113122
data() {
114123
return {
@@ -185,6 +194,10 @@ export default {
185194
},
186195
187196
clickOption(option) {
197+
if (this.disabled || this.readOnly) {
198+
return;
199+
}
200+
188201
this.$emit('onClickOption', option);
189202
},
190203
},

src/scss/_variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Searchable listbox
22
$msl-multi-select-items-box-border-color: #5b5d66 !default;
3+
$msl-multi-select-items-box-disabled-border-color: #d2d2d2 !default;
34
$msl-multi-select-item-border-bottom-color: #252b45 !default;
45
$msl-multi-select-item-hover-bg: #3858e7 !default;
56
$msl-multi-select-item-hover-font-color: #fff !default;

src/scss/modules/_multi-select.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
}
2020
}
2121

22+
.msl-multi-select__action--disabled {
23+
cursor: default;
24+
25+
&:hover {
26+
color: inherit;
27+
}
28+
}
29+
2230
.msl-multi-select__action-select-all {
2331
margin-bottom: 20px;
2432
}

src/scss/modules/_searchable-list.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
overflow-x: hidden;
1616
}
1717

18+
.msl-searchable-list__items--disabled {
19+
border: 1px solid $msl-multi-select-items-box-disabled-border-color;
20+
}
21+
1822
.msl-searchable-list__no-item {
1923
font-size: 0.8em;
2024
padding: 5px 10px;
@@ -30,6 +34,19 @@
3034
background: $msl-multi-select-item-hover-bg;
3135
color: $msl-multi-select-item-hover-font-color;
3236
}
37+
38+
.msl-searchable-list__items--disabled & {
39+
border-bottom: 1px solid $msl-multi-select-items-box-disabled-border-color;
40+
}
41+
}
42+
43+
.msl-searchable-list__item--disabled {
44+
cursor: default;
45+
46+
&:hover {
47+
background: transparent;
48+
color: inherit;
49+
}
3350
}
3451

3552

0 commit comments

Comments
 (0)