]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-forms/select/select-tags.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / select / select-tags.component.ts
1 import { Component, Input, forwardRef } from '@angular/core'
2 import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
3
4 @Component({
5 selector: 'my-select-tags',
6 styleUrls: [ './select-shared.component.scss', './select-tags.component.scss' ],
7 templateUrl: './select-tags.component.html',
8 providers: [
9 {
10 provide: NG_VALUE_ACCESSOR,
11 useExisting: forwardRef(() => SelectTagsComponent),
12 multi: true
13 }
14 ]
15 })
16 export class SelectTagsComponent implements ControlValueAccessor {
17 @Input() availableItems: string[] = []
18 @Input() selectedItems: string[] = []
19 @Input() placeholder = $localize`Enter a new tag`
20
21 propagateChange = (_: any) => { /* empty */ }
22
23 writeValue (items: string[]) {
24 this.selectedItems = items
25 this.propagateChange(this.selectedItems)
26 }
27
28 registerOnChange (fn: (_: any) => void) {
29 this.propagateChange = fn
30 }
31
32 registerOnTouched () {
33 // Unused
34 }
35
36 onModelChange () {
37 this.propagateChange(this.selectedItems)
38 }
39 }