|
| 1 | +import {NgForOf} from '@angular/common'; |
| 2 | +import {ChangeDetectionStrategy, Component} from '@angular/core'; |
| 3 | +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; |
| 4 | +import {tuiIsString} from '@taiga-ui/cdk'; |
| 5 | +import {TUI_ANIMATIONS_SPEED, TuiDataList, TuiRoot, TuiTextfield} from '@taiga-ui/core'; |
| 6 | +import { |
| 7 | + TuiCheckbox, |
| 8 | + TuiChevron, |
| 9 | + TuiFilterByInputPipe, |
| 10 | + TuiInputChip, |
| 11 | + TuiMultiSelect, |
| 12 | + TuiRadio, |
| 13 | + TuiSwitch, |
| 14 | +} from '@taiga-ui/kit'; |
| 15 | + |
| 16 | +interface User { |
| 17 | + readonly name: string; |
| 18 | + readonly index: number; |
| 19 | +} |
| 20 | + |
| 21 | +@Component({ |
| 22 | + standalone: true, |
| 23 | + imports: [ |
| 24 | + FormsModule, |
| 25 | + NgForOf, |
| 26 | + ReactiveFormsModule, |
| 27 | + TuiCheckbox, |
| 28 | + TuiChevron, |
| 29 | + TuiDataList, |
| 30 | + TuiFilterByInputPipe, |
| 31 | + TuiInputChip, |
| 32 | + TuiMultiSelect, |
| 33 | + TuiRadio, |
| 34 | + TuiRoot, |
| 35 | + TuiSwitch, |
| 36 | + TuiTextfield, |
| 37 | + ], |
| 38 | + template: ` |
| 39 | + <!-- @note: the host application on Taiga v3 sets global styles first --> |
| 40 | + <!-- https://github.com/taiga-family/taiga-ui/issues/11927 --> |
| 41 | + <style> |
| 42 | + [tuiAppearance]:disabled:not([data-state]), |
| 43 | + [tuiAppearance][data-state='disabled'] { |
| 44 | + pointer-events: none; |
| 45 | + opacity: var(--tui-disabled-opacity); |
| 46 | + } |
| 47 | + </style> |
| 48 | +
|
| 49 | + <tui-root> |
| 50 | + <label tuiLabel> |
| 51 | + <!-- insert checkbox styles before open dropdown --> |
| 52 | + <input |
| 53 | + tuiCheckbox |
| 54 | + type="checkbox" |
| 55 | + [ngModel]="checkbox" |
| 56 | + /> |
| 57 | +
|
| 58 | + Initially checked |
| 59 | + </label> |
| 60 | +
|
| 61 | + <br /> |
| 62 | +
|
| 63 | + <label tuiLabel> |
| 64 | + Working with objects |
| 65 | + <tui-textfield |
| 66 | + multi |
| 67 | + tuiChevron |
| 68 | + [disabledItemHandler]="strings" |
| 69 | + [stringify]="stringify" |
| 70 | + > |
| 71 | + <input |
| 72 | + tuiInputChip |
| 73 | + [placeholder]="objects.length ? '' : 'Picking objects'" |
| 74 | + [(ngModel)]="objects" |
| 75 | + /> |
| 76 | + <tui-input-chip *tuiItem /> |
| 77 | + <tui-data-list *tuiTextfieldDropdown> |
| 78 | + <tui-opt-group |
| 79 | + label="Pythons" |
| 80 | + tuiMultiSelectGroup |
| 81 | + > |
| 82 | + <button |
| 83 | + *ngFor="let user of users | tuiFilterByInput" |
| 84 | + new |
| 85 | + tuiOption |
| 86 | + [value]="user" |
| 87 | + > |
| 88 | + {{ user.name }} |
| 89 | + </button> |
| 90 | + </tui-opt-group> |
| 91 | + </tui-data-list> |
| 92 | + </tui-textfield> |
| 93 | + </label> |
| 94 | + </tui-root> |
| 95 | + `, |
| 96 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 97 | + providers: [{provide: TUI_ANIMATIONS_SPEED, useValue: 0}], |
| 98 | +}) |
| 99 | +export class TestInputDate { |
| 100 | + protected checkbox = true; |
| 101 | + |
| 102 | + protected readonly items = [ |
| 103 | + 'John Cleese', |
| 104 | + 'Eric Idle', |
| 105 | + 'Michael Palin', |
| 106 | + 'Graham Chapman', |
| 107 | + 'Terry Gilliam', |
| 108 | + 'Terry Jones', |
| 109 | + ]; |
| 110 | + |
| 111 | + protected readonly users = this.items.map((name, index) => ({name, index})); |
| 112 | + |
| 113 | + protected objects: User[] = this.users; |
| 114 | + |
| 115 | + protected readonly strings = tuiIsString; |
| 116 | + protected readonly stringify = ({name}: User): string => name; |
| 117 | + protected readonly disabled = (item: string): boolean => !this.items.includes(item); |
| 118 | +} |
| 119 | + |
| 120 | +describe('InputChip', () => { |
| 121 | + beforeEach(() => cy.mount(TestInputDate)); |
| 122 | + |
| 123 | + it('verify dropdown functionality with interactive checkbox', () => { |
| 124 | + cy.get('tui-textfield').click(); |
| 125 | + |
| 126 | + cy.compareSnapshot('input-chip-multi-select'); |
| 127 | + }); |
| 128 | +}); |
0 commit comments