-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput-chips.component.ts
More file actions
53 lines (47 loc) · 1.44 KB
/
input-chips.component.ts
File metadata and controls
53 lines (47 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
ChangeDetectionStrategy,
Component,
ContentChildren,
Input,
QueryList,
ViewChild,
booleanAttribute,
numberAttribute,
} from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatChipListbox, MatChipsModule } from '@angular/material/chips';
import { MatFormFieldModule } from '@angular/material/form-field';
import { InputDirective } from '../input.directive';
import { InputChipComponent } from './input-chip.component';
@Component({
selector: 'pro-input-chips[label]',
templateUrl: './input-chips.component.html',
imports: [
FormsModule,
MatChipsModule,
MatFormFieldModule,
ReactiveFormsModule,
],
styleUrl: './input-chips.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
export class InputChipsComponent extends InputDirective<string> {
@ContentChildren(InputChipComponent)
public readonly chips = new QueryList<InputChipComponent>();
@ViewChild(MatChipListbox)
public readonly matChipListbox: MatChipListbox | undefined;
@Input({ transform: numberAttribute })
public max: number | string | undefined;
@Input({ transform: booleanAttribute })
public multiple = false;
@Input() public compareWith: MatChipListbox['compareWith'] = (
optionValue,
selectedValue,
) => {
return (
JSON.stringify(optionValue) === JSON.stringify(selectedValue) ||
optionValue === selectedValue
);
};
}