Skip to content

Commit

Permalink
Merge pull request #79 from nih-sparc/make-multiselect-text-interactive
Browse files Browse the repository at this point in the history
Make multiselect text interactive
  • Loading branch information
egauzens authored Jan 31, 2022
2 parents 8343a64 + d0e575b commit 15b71d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nih-sparc/sparc-design-system-components",
"version": "0.23.0",
"version": "0.24.0",
"private": false,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
31 changes: 30 additions & 1 deletion src/components/MultiSelect/src/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ref="cascader"
>
<template slot-scope="{ node, data }">
<span>{{ data.label }}</span>
<span :class="`${node.isLeaf ? 'leaf-node-label' : ''}`" @click="labelClicked(node)">{{ data.label }}</span>
<span v-if="!node.isLeaf && numFiltersApplied(data) != 0"> ({{ numFiltersApplied(data) }}) </span>
</template>
</el-cascader>
Expand Down Expand Up @@ -101,6 +101,31 @@ export default {
this.previouslySelectedArray = [...this.selectedArray]
},
methods:{
labelClicked(node) {
if (node.isDisabled || node.hasChildren) {
return
}
const newlySelectedArray = []
this.previouslySelectedArray = [...this.selectedArray]
if (this.selectedArray.length) {
this.selectedArray.forEach(n => {
newlySelectedArray.push(n)
})
}
if (!node.checked) {
newlySelectedArray.unshift(node.path)
} else {
if (newlySelectedArray.length) {
const map = newlySelectedArray.map(n => n.join(','))
const idx = map.findIndex(q => q === node.path.join(','))
if (idx > -1) {
newlySelectedArray.splice(idx, 1)
}
}
}
this.selectedArray = newlySelectedArray
this.onSelectionChange()
},
addShowAllNode(option, isMultilevel) {
const showAllNode = {
value: option.value,
Expand Down Expand Up @@ -332,6 +357,10 @@ export default {
.el-cascader-node__label {
padding: 0;
}
.leaf-node-label {
display: inline-block;
width: 100%;
}
.multilevel-select-filter {
color: $lightGrey;
position: absolute;
Expand Down

0 comments on commit 15b71d8

Please sign in to comment.