Last active
June 1, 2020 18:57
-
-
Save Dornhoth/29d1c708b302f522b49b7e4e89f28afb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class MultiselectComponent implements ControlValueAccessor { | |
[...] | |
open = false; | |
disabled = false; | |
[...] | |
writeValue(items: Array<ListItem>): void { | |
this.selectedItems = items || []; | |
this.onChange(this.selectedItems); | |
} | |
registerOnChange(fn: any): void { | |
this.onChange = fn; | |
} | |
registerOnTouched(fn: any): void { | |
this.onTouch = fn; | |
} | |
setDisabledState?(isDisabled: boolean): void { | |
this.disabled = isDisabled; | |
} | |
onItemClick(item: ListItem) { | |
if (!this.disabled) { | |
const found = this.isItemAlreadySelected(item); | |
if (!found) { | |
this.select(item); | |
} else { | |
this.unselect(item); | |
} | |
this.onChange(this.items); | |
} | |
} | |
[...] | |
toggleDropdown() { | |
if (!this.disabled) { | |
this.open = !this.open; | |
} | |
} | |
closeDropdown() { | |
this.open = false; | |
} | |
[...] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment