Last active
June 1, 2020 18:19
-
-
Save Dornhoth/1ea4c71a3460a64a1d61d5f4627563e7 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 { | |
| [...] | |
| 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 { | |
| 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 { | |
| throw new Error('Method not implemented.'); | |
| } | |
| [...] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment