From 10ecc2c81695e343b41a0f6b0ca4f51b715f6cdc Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 6 Apr 2019 14:00:39 -0400 Subject: [PATCH] make sure to use filtered selected keys --- src/components/selectable_list/selectable_list.js | 14 ++++++++++---- src/components/selectable_list/selectable_list.vue | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/selectable_list/selectable_list.js b/src/components/selectable_list/selectable_list.js index b8bd4f75..10980d46 100644 --- a/src/components/selectable_list/selectable_list.js +++ b/src/components/selectable_list/selectable_list.js @@ -22,11 +22,17 @@ const SelectableList = { } }, computed: { + allKeys () { + return this.items.map(this.getKey) + }, + filteredSelected () { + return this.allKeys.filter(key => this.selected.indexOf(key) !== -1) + }, allSelected () { - return !this.items.find(item => !this.isSelected(item)) + return this.filteredSelected.length === this.items.length }, noneSelected () { - return !this.items.find(item => this.isSelected(item)) + return this.filteredSelected.length === 0 }, someSelected () { return !this.allSelected && !this.noneSelected @@ -34,7 +40,7 @@ const SelectableList = { }, methods: { isSelected (item) { - return this.selected.indexOf(this.getKey(item)) !== -1 + return this.filteredSelected.indexOf(this.getKey(item)) !== -1 }, toggle (checked, item) { const key = this.getKey(item) @@ -49,7 +55,7 @@ const SelectableList = { }, toggleAll (value) { if (value) { - this.selected = this.items.map(this.getKey) + this.selected = this.allKeys.slice(0) } else { this.selected = [] } diff --git a/src/components/selectable_list/selectable_list.vue b/src/components/selectable_list/selectable_list.vue index 5b8693c4..80306594 100644 --- a/src/components/selectable_list/selectable_list.vue +++ b/src/components/selectable_list/selectable_list.vue @@ -5,7 +5,7 @@ {{ $t('selectable_list.select_all') }}
- +