Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Created June 1, 2020 18:03
Show Gist options
  • Save Dornhoth/514351ae7aeb92279e987e4e0f14aa3e to your computer and use it in GitHub Desktop.
Save Dornhoth/514351ae7aeb92279e987e4e0f14aa3e to your computer and use it in GitHub Desktop.
export class MultiselectComponent implements ControlValueAccessor {
[...]
private onChange = (_: Array<ListItem>) => { };
private onTouch = () => { };
@HostListener('document:click', ['$event.target'])
public onClick(targetElement) {
const clickedInside = this.multiselect.nativeElement.contains(targetElement);
if (!clickedInside) {
this.closeDropdown();
this.onTouch();
}
}
@HostListener('blur')
public onTouched() {
this.closeDropdown();
this.onTouch();
}
writeValue(items: Array<ListItem>): void {
throw new Error('Method not implemented.');
}
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouch = fn;
}
setDisabledState?(isDisabled: boolean): void {
throw new Error('Method not implemented.');
}
[...]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment