CheckboxList story amends

This commit is contained in:
leekelleher
2024-03-19 09:29:07 +00:00
parent 031a976ac5
commit 3c5f48e11b
2 changed files with 11 additions and 11 deletions

View File

@@ -12,9 +12,9 @@ export class UmbInputCheckboxListElement extends FormControlMixin(UmbLitElement)
#selection: Array<string> = [];
@property({ type: Array })
public set selection(keys: Array<string>) {
this.#selection = keys;
super.value = keys.join(',');
public set selection(values: Array<string>) {
this.#selection = values;
super.value = values.join(',');
}
public get selection(): Array<string> {
return this.#selection;
@@ -32,16 +32,16 @@ export class UmbInputCheckboxListElement extends FormControlMixin(UmbLitElement)
#onChange(e: UUIBooleanInputEvent) {
e.stopPropagation();
if (e.target.checked) this.selection = [...this.selection, e.target.value];
else this.#removeFromSelection(this.selection.findIndex((key) => e.target.value === key));
else this.#removeFromSelection(this.selection.findIndex((value) => e.target.value === value));
this.dispatchEvent(new UmbChangeEvent());
}
#removeFromSelection(index: number) {
if (index == -1) return;
const keys = [...this.selection];
keys.splice(index, 1);
this.selection = keys;
const values = [...this.selection];
values.splice(index, 1);
this.selection = values;
}
render() {

View File

@@ -14,13 +14,13 @@ export const Overview: Story = {
args: {
list: [
{
key: 'isAwesome',
value: 'Umbraco is awesome?',
label: 'Umbraco is awesome?',
value: 'isAwesome',
checked: true,
},
{
key: 'attendingCodeGarden',
value: 'Attending CodeGarden?',
label: 'Attending CodeGarden?',
value: 'attendingCodeGarden',
checked: false,
},
],