Skip to content

Commit

Permalink
fix: unit tests now all pass (fixed issue with KvCheckboxList)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyersituations committed Jun 5, 2024
1 parent 0e1fbd5 commit dcba7a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
21 changes: 4 additions & 17 deletions .storybook/stories/KvCheckboxList.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,12 @@ export default {
component: KvCheckboxList,
};

const story = (args) => {
const template = (_args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { KvCheckboxList },
template: `<kv-checkbox-list
:show-select-all="showSelectAll"
:items="items"
:selected-values="selectedValues" />`,
})
template.args = args;
return template;
};

const items = [...Array(4)].map((_, i) => ({ value: `${i}`, title: `Option ${i}` }));

export const Default = story({ items });
export const Default = { args: { items } };

export const ShowSelectAll = story({ items, showSelectAll: true });
export const ShowSelectAll = { args: { items, showSelectAll: true } };

export const SelectedValues = story({ items, selectedValues: items.slice(0, 2).map(i => i.value) });
export const SelectedValues = { args: { items, selectedValues: items.slice(0, 2).map(i => i.value) } };

export const Disabled = story({ items: items.map(i => ({ ...i, disabled: true })) });
export const Disabled = { args: { items: items.map(i => ({ ...i, disabled: true })) } };
12 changes: 7 additions & 5 deletions src/components/Kv/KvCheckboxList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
*/
selectedValues: {
type: Array,
default: () => []
default: () => ([]),
},
},
data() {
Expand All @@ -63,14 +63,16 @@ export default {
methods: {
toggleSelectAll() {
const isAll = this.isAllSelected;
const updatedSelected = [...this.selected];
this.items.forEach(item => {
const index = this.selected.indexOf(item.value);
const index = updatedSelected.indexOf(item.value);
const exists = index !== -1;
if (isAll) {
if (exists) this.selected.splice(index, 1);
} else if (!exists) this.selected.push(item.value);
if (exists) updatedSelected.splice(index, 1);
} else if (!exists) updatedSelected.push(item.value);
});
this.updateSelected(this.selected, undefined, true);
this.selected = updatedSelected;
this.updateSelected(updatedSelected, undefined, true);
},
updateSelected(values, changed, wasSelectAll) {
this.$emit('updated', { values: [...values], changed, wasSelectAll });
Expand Down

0 comments on commit dcba7a7

Please sign in to comment.