• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.46
/projects/igniteui-angular/src/lib/chips/chip.component.ts
1
import {
2
    Component,
3
    ChangeDetectorRef,
4
    EventEmitter,
5
    ElementRef,
6
    HostBinding,
7
    HostListener,
8
    Input,
9
    Output,
10
    ViewChild,
11
    Renderer2,
12
    TemplateRef,
13
    OnDestroy,
14
    booleanAttribute,
15
    OnInit,
16
    Inject
17
} from '@angular/core';
18
import { IgxDragDirective, IDragBaseEventArgs, IDragStartEventArgs, IDropBaseEventArgs, IDropDroppedEventArgs, IgxDropDirective } from '../directives/drag-drop/drag-drop.directive';
19
import { IBaseEventArgs, mkenum } from '../core/utils';
20
import { ChipResourceStringsEN, IChipResourceStrings } from '../core/i18n/chip-resources';
21
import { Subject } from 'rxjs';
22
import { IgxIconComponent } from '../icon/icon.component';
23
import { NgClass, NgTemplateOutlet, NgIf, DOCUMENT } from '@angular/common';
24
import { getCurrentResourceStrings } from '../core/i18n/resources';
25
import { Size } from '../grids/common/enums';
26

27
export const IgxChipTypeVariant = /*@__PURE__*/mkenum({
2✔
28
    PRIMARY: 'primary',
29
    INFO: 'info',
30
    SUCCESS: 'success',
31
    WARNING: 'warning',
32
    DANGER: 'danger'
33
});
34

35
export interface IBaseChipEventArgs extends IBaseEventArgs {
36
    originalEvent: IDragBaseEventArgs | IDropBaseEventArgs | KeyboardEvent | MouseEvent | TouchEvent;
37
    owner: IgxChipComponent;
38
}
39

40
export interface IChipClickEventArgs extends IBaseChipEventArgs {
41
    cancel: boolean;
42
}
43

44
export interface IChipKeyDownEventArgs extends IBaseChipEventArgs {
45
    originalEvent: KeyboardEvent;
46
    cancel: boolean;
47
}
48

49
export interface IChipEnterDragAreaEventArgs extends IBaseChipEventArgs {
50
    dragChip: IgxChipComponent;
51
}
52

53
export interface IChipSelectEventArgs extends IBaseChipEventArgs {
54
    cancel: boolean;
55
    selected: boolean;
56
}
57

58
let CHIP_ID = 0;
2✔
59

60
/**
61
 * Chip is compact visual component that displays information in an obround.
62
 *
63
 * @igxModule IgxChipsModule
64
 *
65
 * @igxTheme igx-chip-theme
66
 *
67
 * @igxKeywords chip
68
 *
69
 * @igxGroup display
70
 *
71
 * @remarks
72
 * The Ignite UI Chip can be templated, deleted, and selected.
73
 * Multiple chips can be reordered and visually connected to each other.
74
 * Chips reside in a container called chips area which is responsible for managing the interactions between the chips.
75
 *
76
 * @example
77
 * ```html
78
 * <igx-chip class="chipStyle" [id]="901" [draggable]="true" [removable]="true" (remove)="chipRemoved($event)">
79
 *    <igx-avatar class="chip-avatar-resized" igxPrefix></igx-avatar>
80
 * </igx-chip>
81
 * ```
82
 */
83
@Component({
84
    selector: 'igx-chip',
85
    templateUrl: 'chip.component.html',
86
    imports: [IgxDropDirective, IgxDragDirective, NgClass, NgTemplateOutlet, NgIf, IgxIconComponent]
87
})
88
export class IgxChipComponent implements OnInit, OnDestroy {
2✔
89

90
    /**
91
     * Sets/gets the variant of the chip.
92
     *
93
     * @remarks
94
     * Allowed values are `primary`, `info`, `success`, `warning`, `danger`.
95
     * Providing an invalid value won't change the chip.
96
     *
97
     * @example
98
     * ```html
99
     * <igx-chip [variant]="success"></igx-chip>
100
     * ```
101
     */
102
    @Input()
103
    public variant: string | typeof IgxChipTypeVariant;
104
    /**
105
     * Sets the value of `id` attribute. If not provided it will be automatically generated.
106
     *
107
     * @example
108
     * ```html
109
     * <igx-chip [id]="'igx-chip-1'"></igx-chip>
110
     * ```
111
     */
112
    @HostBinding('attr.id')
113
    @Input()
114
    public id = `igx-chip-${CHIP_ID++}`;
149✔
115

116
    /**
117
     * Returns the `role` attribute of the chip.
118
     *
119
     * @example
120
     * ```typescript
121
     * let chipRole = this.chip.role;
122
     * ```
123
     */
124
    @HostBinding('attr.role')
125
    public role = 'option';
149✔
126

127
    /**
128
     * Sets the value of `tabindex` attribute. If not provided it will use the element's tabindex if set.
129
     *
130
     * @example
131
     * ```html
132
     * <igx-chip [id]="'igx-chip-1'" [tabIndex]="1"></igx-chip>
133
     * ```
134
     */
135
    @HostBinding('attr.tabIndex')
136
    @Input()
137
    public set tabIndex(value: number) {
UNCOV
138
        this._tabIndex = value;
×
139
    }
140

141
    public get tabIndex() {
142
        if (this._tabIndex !== null) {
2,448!
UNCOV
143
            return this._tabIndex;
×
144
        }
145
        return !this.disabled ? 0 : null;
2,448!
146
    }
147

148
    /**
149
     * Stores data related to the chip.
150
     *
151
     * @example
152
     * ```html
153
     * <igx-chip [data]="{ value: 'Country' }"></igx-chip>
154
     * ```
155
     */
156
    @Input()
157
    public data: any;
158

159
    /**
160
     * Defines if the `IgxChipComponent` can be dragged in order to change it's position.
161
     * By default it is set to false.
162
     *
163
     * @example
164
     * ```html
165
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true"></igx-chip>
166
     * ```
167
     */
168
    @Input({ transform: booleanAttribute })
169
    public draggable = false;
149✔
170

171
    /**
172
     * Enables/disables the draggable element animation when the element is released.
173
     * By default it's set to true.
174
     *
175
     * @example
176
     * ```html
177
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true" [animateOnRelease]="false"></igx-chip>
178
     * ```
179
     */
180
    @Input({ transform: booleanAttribute })
181
    public animateOnRelease = true;
149✔
182

183
    /**
184
     * Enables/disables the hiding of the base element that has been dragged.
185
     * By default it's set to true.
186
     *
187
     * @example
188
     * ```html
189
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true" [hideBaseOnDrag]="false"></igx-chip>
190
     * ```
191
     */
192
    @Input({ transform: booleanAttribute })
193
    public hideBaseOnDrag = true;
149✔
194

195
    /**
196
     * Defines if the `IgxChipComponent` should render remove button and throw remove events.
197
     * By default it is set to false.
198
     *
199
     * @example
200
     * ```html
201
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true" [removable]="true"></igx-chip>
202
     * ```
203
     */
204
    @Input({ transform: booleanAttribute })
205
    public removable = false;
149✔
206

207
    /**
208
     * Overrides the default icon that the chip applies to the remove button.
209
     *
210
     * @example
211
     * ```html
212
     * <igx-chip [id]="chip.id" [removable]="true" [removeIcon]="iconTemplate"></igx-chip>
213
     * <ng-template #iconTemplate><igx-icon>delete</igx-icon></ng-template>
214
     * ```
215
     */
216
    @Input()
217
    public removeIcon: TemplateRef<any>;
218

219
    /**
220
     * Defines if the `IgxChipComponent` can be selected on click or through navigation,
221
     * By default it is set to false.
222
     *
223
     * @example
224
     * ```html
225
     * <igx-chip [id]="chip.id" [draggable]="true" [removable]="true" [selectable]="true"></igx-chip>
226
     * ```
227
     */
228
    @Input({ transform: booleanAttribute })
229
    public selectable = false;
149✔
230

231
    /**
232
     * Overrides the default icon that the chip applies when it is selected.
233
     *
234
     * @example
235
     * ```html
236
     * <igx-chip [id]="chip.id" [selectable]="true" [selectIcon]="iconTemplate"></igx-chip>
237
     * <ng-template #iconTemplate><igx-icon>done_outline</igx-icon></ng-template>
238
     * ```
239
     */
240
    @Input()
241
    public selectIcon: TemplateRef<any>;
242

243
    /**
244
     * @hidden
245
     * @internal
246
     */
247
    @Input()
248
    public class = '';
149✔
249

250
    /**
251
     * Disables the `IgxChipComponent`. When disabled it restricts user interactions
252
     * like focusing on click or tab, selection on click or Space, dragging.
253
     * By default it is set to false.
254
     *
255
     * @example
256
     * ```html
257
     * <igx-chip [id]="chip.id" [disabled]="true"></igx-chip>
258
     * ```
259
     */
260
    @HostBinding('class.igx-chip--disabled')
261
    @Input({ transform: booleanAttribute })
262
    public disabled = false;
149✔
263

264
    /**
265
     * Sets the `IgxChipComponent` selected state.
266
     *
267
     * @example
268
     * ```html
269
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" [selected]="true">
270
     * ```
271
     *
272
     * Two-way data binding:
273
     * ```html
274
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" [(selected)]="model.isSelected">
275
     * ```
276
     */
277
    @HostBinding('attr.aria-selected')
278
    @Input({ transform: booleanAttribute })
279
    public set selected(newValue: boolean) {
UNCOV
280
        this.changeSelection(newValue);
×
281
    }
282

283
    /**
284
     * Returns if the `IgxChipComponent` is selected.
285
     *
286
     * @example
287
     * ```typescript
288
     * @ViewChild('myChip')
289
     * public chip: IgxChipComponent;
290
     * selectedChip(){
291
     *     let selectedChip = this.chip.selected;
292
     * }
293
     * ```
294
     */
295
    public get selected() {
296
        return this._selected;
2,448✔
297
    }
298

299
    /**
300
     * @hidden
301
     * @internal
302
     */
303
    @Output()
304
    public selectedChange = new EventEmitter<boolean>();
149✔
305

306
    /**
307
     * Sets the `IgxChipComponent` background color.
308
     * The `color` property supports string, rgb, hex.
309
     *
310
     * @example
311
     * ```html
312
     * <igx-chip #myChip [id]="'igx-chip-1'" [color]="'#ff0000'"></igx-chip>
313
     * ```
314
     */
315
    @Input()
316
    public set color(newColor) {
UNCOV
317
        this.chipArea.nativeElement.style.backgroundColor = newColor;
×
318
    }
319

320
    /**
321
     * Returns the background color of the `IgxChipComponent`.
322
     *
323
     * @example
324
     * ```typescript
325
     * @ViewChild('myChip')
326
     * public chip: IgxChipComponent;
327
     * ngAfterViewInit(){
328
     *     let chipColor = this.chip.color;
329
     * }
330
     * ```
331
     */
332
    public get color() {
UNCOV
333
        return this.chipArea.nativeElement.style.backgroundColor;
×
334
    }
335

336
    /**
337
     * An accessor that sets the resource strings.
338
     * By default it uses EN resources.
339
     */
340
    @Input()
341
    public set resourceStrings(value: IChipResourceStrings) {
342
        this._resourceStrings = Object.assign({}, this._resourceStrings, value);
×
343
    }
344

345
    /**
346
     * An accessor that returns the resource strings.
347
     */
348
    public get resourceStrings(): IChipResourceStrings {
349
        return this._resourceStrings;
1,224✔
350
    }
351

352
    /**
353
     * Emits an event when the `IgxChipComponent` moving starts.
354
     * Returns the moving `IgxChipComponent`.
355
     *
356
     * @example
357
     * ```html
358
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (moveStart)="moveStarted($event)">
359
     * ```
360
     */
361
    @Output()
362
    public moveStart = new EventEmitter<IBaseChipEventArgs>();
149✔
363

364
    /**
365
     * Emits an event when the `IgxChipComponent` moving ends.
366
     * Returns the moved `IgxChipComponent`.
367
     *
368
     * @example
369
     * ```html
370
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (moveEnd)="moveEnded($event)">
371
     * ```
372
     */
373
    @Output()
374
    public moveEnd = new EventEmitter<IBaseChipEventArgs>();
149✔
375

376
    /**
377
     * Emits an event when the `IgxChipComponent` is removed.
378
     * Returns the removed `IgxChipComponent`.
379
     *
380
     * @example
381
     * ```html
382
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (remove)="remove($event)">
383
     * ```
384
     */
385
    @Output()
386
    public remove = new EventEmitter<IBaseChipEventArgs>();
149✔
387

388
    /**
389
     * Emits an event when the `IgxChipComponent` is clicked.
390
     * Returns the clicked `IgxChipComponent`, whether the event should be canceled.
391
     *
392
     * @example
393
     * ```html
394
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (click)="chipClick($event)">
395
     * ```
396
     */
397
    @Output()
398
    public chipClick = new EventEmitter<IChipClickEventArgs>();
149✔
399

400
    /**
401
     * Emits event when the `IgxChipComponent` is selected/deselected.
402
     * Returns the selected chip reference, whether the event should be canceled, what is the next selection state and
403
     * when the event is triggered by interaction `originalEvent` is provided, otherwise `originalEvent` is `null`.
404
     *
405
     * @example
406
     * ```html
407
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" (selectedChanging)="chipSelect($event)">
408
     * ```
409
     */
410
    @Output()
411
    public selectedChanging = new EventEmitter<IChipSelectEventArgs>();
149✔
412

413
    /**
414
     * Emits event when the `IgxChipComponent` is selected/deselected and any related animations and transitions also end.
415
     *
416
     * @example
417
     * ```html
418
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" (selectedChanged)="chipSelectEnd($event)">
419
     * ```
420
     */
421
    @Output()
422
    public selectedChanged = new EventEmitter<IBaseChipEventArgs>();
149✔
423

424
    /**
425
     * Emits an event when the `IgxChipComponent` keyboard navigation is being used.
426
     * Returns the focused/selected `IgxChipComponent`, whether the event should be canceled,
427
     * if the `alt`, `shift` or `control` key is pressed and the pressed key name.
428
     *
429
     * @example
430
     * ```html
431
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (keyDown)="chipKeyDown($event)">
432
     * ```
433
     */
434
    @Output()
435
    public keyDown = new EventEmitter<IChipKeyDownEventArgs>();
149✔
436

437
    /**
438
     * Emits an event when the `IgxChipComponent` has entered the `IgxChipsAreaComponent`.
439
     * Returns the target `IgxChipComponent`, the drag `IgxChipComponent`, as  well as
440
     * the original drop event arguments.
441
     *
442
     * @example
443
     * ```html
444
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragEnter)="chipEnter($event)">
445
     * ```
446
     */
447
    @Output()
448
    public dragEnter = new EventEmitter<IChipEnterDragAreaEventArgs>();
149✔
449

450
    /**
451
     * Emits an event when the `IgxChipComponent` has left the `IgxChipsAreaComponent`.
452
     * Returns the target `IgxChipComponent`, the drag `IgxChipComponent`, as  well as
453
     * the original drop event arguments.
454
     *
455
     * @example
456
     * ```html
457
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragLeave)="chipLeave($event)">
458
     * ```
459
     */
460
    @Output()
461
    public dragLeave = new EventEmitter<IChipEnterDragAreaEventArgs>();
149✔
462

463
    /**
464
     * Emits an event when the `IgxChipComponent` is over the `IgxChipsAreaComponent`.
465
     * Returns the target `IgxChipComponent`, the drag `IgxChipComponent`, as  well as
466
     * the original drop event arguments.
467
     *
468
     * @example
469
     * ```html
470
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragOver)="chipOver($event)">
471
     * ```
472
     */
473
    @Output()
474
    public dragOver = new EventEmitter<IChipEnterDragAreaEventArgs>();
149✔
475

476
    /**
477
     * Emits an event when the `IgxChipComponent` has been dropped in the `IgxChipsAreaComponent`.
478
     * Returns the target `IgxChipComponent`, the drag `IgxChipComponent`, as  well as
479
     * the original drop event arguments.
480
     *
481
     * @example
482
     * ```html
483
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragDrop)="chipLeave($event)">
484
     * ```
485
     */
486
    @Output()
487
    public dragDrop = new EventEmitter<IChipEnterDragAreaEventArgs>();
149✔
488

489
    @HostBinding('class.igx-chip')
490
    protected defaultClass = 'igx-chip';
149✔
491

492
    @HostBinding('class.igx-chip--primary')
493
    protected get isPrimary() {
494
        return this.variant === IgxChipTypeVariant.PRIMARY;
1,224✔
495
    }
496

497
    @HostBinding('class.igx-chip--info')
498
    protected get isInfo() {
499
        return this.variant === IgxChipTypeVariant.INFO;
1,224✔
500
    }
501

502
    @HostBinding('class.igx-chip--success')
503
    protected get isSuccess() {
504
        return this.variant === IgxChipTypeVariant.SUCCESS;
1,224✔
505
    }
506

507
    @HostBinding('class.igx-chip--warning')
508
    protected get isWarning() {
509
        return this.variant === IgxChipTypeVariant.WARNING;
1,224✔
510
    }
511

512
    @HostBinding('class.igx-chip--danger')
513
    protected get isDanger() {
514
        return this.variant === IgxChipTypeVariant.DANGER;
1,224✔
515
    }
516

517
    /**
518
     * Property that contains a reference to the `IgxDragDirective` the `IgxChipComponent` uses for dragging behavior.
519
     *
520
     * @example
521
     * ```html
522
     * <igx-chip [id]="chip.id" [draggable]="true"></igx-chip>
523
     * ```
524
     * ```typescript
525
     * onMoveStart(event: IBaseChipEventArgs){
526
     *     let dragDirective = event.owner.dragDirective;
527
     * }
528
     * ```
529
     */
530
    @ViewChild('chipArea', { read: IgxDragDirective, static: true })
531
    public dragDirective: IgxDragDirective;
532

533
    /**
534
     * @hidden
535
     * @internal
536
     */
537
    @ViewChild('chipArea', { read: ElementRef, static: true })
538
    public chipArea: ElementRef;
539

540
    /**
541
     * @hidden
542
     * @internal
543
     */
544
    @ViewChild('defaultRemoveIcon', { read: TemplateRef, static: true })
545
    public defaultRemoveIcon: TemplateRef<any>;
546

547
    /**
548
     * @hidden
549
     * @internal
550
     */
551
    @ViewChild('defaultSelectIcon', { read: TemplateRef, static: true })
552
    public defaultSelectIcon: TemplateRef<any>;
553

554
    /**
555
     * @hidden
556
     * @internal
557
     */
558
    public get removeButtonTemplate() {
559
        if (!this.disabled) {
1,224✔
560
            return this.removeIcon || this.defaultRemoveIcon;
1,224✔
561
        }
562
    }
563

564
    /**
565
     * @hidden
566
     * @internal
567
     */
568
    public get selectIconTemplate() {
UNCOV
569
        return this.selectIcon || this.defaultSelectIcon;
×
570
    }
571

572
    /**
573
     * @hidden
574
     * @internal
575
     */
576
    public get ghostStyles() {
577
        return { '--ig-size': `${this.chipSize}` };
1,224✔
578
    }
579

580
    /** @hidden @internal */
581
    public get nativeElement() {
582
        return this.ref.nativeElement;
159✔
583
    }
584

585
    /**
586
     * @hidden
587
     * @internal
588
     */
589
    public hideBaseElement = false;
149✔
590

591
    /**
592
     * @hidden
593
     * @internal
594
     */
595
    public destroy$ = new Subject<void>();
149✔
596

597
    protected get chipSize(): Size {
598
        return this.computedStyles?.getPropertyValue('--ig-size') || Size.Medium;
1,224!
599
    }
600
    protected _tabIndex = null;
149✔
601
    protected _selected = false;
149✔
602
    protected _selectedItemClass = 'igx-chip__item--selected';
149✔
603
    protected _movedWhileRemoving = false;
149✔
604
    protected computedStyles;
605
    private _resourceStrings = getCurrentResourceStrings(ChipResourceStringsEN);
149✔
606

607
    constructor(
608
        public cdr: ChangeDetectorRef,
149✔
609
        private ref: ElementRef<HTMLElement>,
149✔
610
        private renderer: Renderer2,
149✔
611
        @Inject(DOCUMENT) public document: any) { }
149✔
612

613
    /**
614
     * @hidden
615
     * @internal
616
     */
617
    @HostListener('keydown', ['$event'])
618
    public keyEvent(event: KeyboardEvent) {
UNCOV
619
        this.onChipKeyDown(event);
×
620
    }
621

622
    /**
623
     * @hidden
624
     * @internal
625
     */
626
    public selectClass(condition: boolean): any {
UNCOV
627
        const SELECT_CLASS = 'igx-chip__select';
×
628

UNCOV
629
        return {
×
630
            [SELECT_CLASS]: condition,
631
            [`${SELECT_CLASS}--hidden`]: !condition
632
        };
633
    }
634

635
    public onSelectTransitionDone(event) {
636
        if (event.target.tagName) {
×
637
            // Trigger onSelectionDone on when `width` property is changed and the target is valid element(not comment).
638
            this.selectedChanged.emit({
×
639
                owner: this,
640
                originalEvent: event
641
            });
642
        }
643
    }
644

645
    /**
646
     * @hidden
647
     * @internal
648
     */
649
    public onChipKeyDown(event: KeyboardEvent) {
UNCOV
650
        const keyDownArgs: IChipKeyDownEventArgs = {
×
651
            originalEvent: event,
652
            owner: this,
653
            cancel: false
654
        };
655

UNCOV
656
        this.keyDown.emit(keyDownArgs);
×
UNCOV
657
        if (keyDownArgs.cancel) {
×
658
            return;
×
659
        }
660

UNCOV
661
        if ((event.key === 'Delete' || event.key === 'Del') && this.removable) {
×
UNCOV
662
            this.remove.emit({
×
663
                originalEvent: event,
664
                owner: this
665
            });
666
        }
667

UNCOV
668
        if ((event.key === ' ' || event.key === 'Spacebar') && this.selectable && !this.disabled) {
×
UNCOV
669
            this.changeSelection(!this.selected, event);
×
670
        }
671

UNCOV
672
        if (event.key !== 'Tab') {
×
UNCOV
673
            event.preventDefault();
×
674
        }
675
    }
676

677
    /**
678
     * @hidden
679
     * @internal
680
     */
681
    public onRemoveBtnKeyDown(event: KeyboardEvent) {
UNCOV
682
        if (event.key === ' ' || event.key === 'Spacebar' || event.key === 'Enter') {
×
UNCOV
683
            this.remove.emit({
×
684
                originalEvent: event,
685
                owner: this
686
            });
687

UNCOV
688
            event.preventDefault();
×
UNCOV
689
            event.stopPropagation();
×
690
        }
691
    }
692

693
    public onRemoveMouseDown(event: PointerEvent | MouseEvent) {
UNCOV
694
        event.stopPropagation();
×
695
    }
696

697
    /**
698
     * @hidden
699
     * @internal
700
     */
701
    public onRemoveClick(event: MouseEvent | TouchEvent) {
UNCOV
702
        this.remove.emit({
×
703
            originalEvent: event,
704
            owner: this
705
        });
706
    }
707

708
    /**
709
     * @hidden
710
     * @internal
711
     */
712
    public onRemoveTouchMove() {
713
        // We don't remove chip if user starting touch interacting on the remove button moves the chip
714
        this._movedWhileRemoving = true;
×
715
    }
716

717
    /**
718
     * @hidden
719
     * @internal
720
     */
721
    public onRemoveTouchEnd(event: TouchEvent) {
722
        if (!this._movedWhileRemoving) {
×
723
            this.onRemoveClick(event);
×
724
        }
725
        this._movedWhileRemoving = false;
×
726
    }
727

728
    /**
729
     * @hidden
730
     * @internal
731
     */
732
    // -----------------------------
733
    // Start chip igxDrag behavior
734
    public onChipDragStart(event: IDragStartEventArgs) {
UNCOV
735
        this.moveStart.emit({
×
736
            originalEvent: event,
737
            owner: this
738
        });
UNCOV
739
        event.cancel = !this.draggable || this.disabled;
×
740
    }
741

742
    /**
743
     * @hidden
744
     * @internal
745
     */
746
    public onChipDragEnd() {
UNCOV
747
        if (this.animateOnRelease) {
×
748
            this.dragDirective.transitionToOrigin();
×
749
        }
750
    }
751

752
    /**
753
     * @hidden
754
     * @internal
755
     */
756
    public onChipMoveEnd(event: IDragBaseEventArgs) {
757
        // moveEnd is triggered after return animation has finished. This happen when we drag and release the chip.
UNCOV
758
        this.moveEnd.emit({
×
759
            originalEvent: event,
760
            owner: this
761
        });
762

UNCOV
763
        if (this.selected) {
×
764
            this.chipArea.nativeElement.focus();
×
765
        }
766
    }
767

768
    /**
769
     * @hidden
770
     * @internal
771
     */
772
    public onChipGhostCreate() {
UNCOV
773
        this.hideBaseElement = this.hideBaseOnDrag;
×
774
    }
775

776
    /**
777
     * @hidden
778
     * @internal
779
     */
780
    public onChipGhostDestroy() {
UNCOV
781
        this.hideBaseElement = false;
×
782
    }
783

784
    /**
785
     * @hidden
786
     * @internal
787
     */
788
    public onChipDragClicked(event: IDragBaseEventArgs) {
UNCOV
789
        const clickEventArgs: IChipClickEventArgs = {
×
790
            originalEvent: event,
791
            owner: this,
792
            cancel: false
793
        };
UNCOV
794
        this.chipClick.emit(clickEventArgs);
×
795

UNCOV
796
        if (!clickEventArgs.cancel && this.selectable && !this.disabled) {
×
UNCOV
797
            this.changeSelection(!this.selected, event);
×
798
        }
799
    }
800
    // End chip igxDrag behavior
801

802
    /**
803
     * @hidden
804
     * @internal
805
     */
806
    // -----------------------------
807
    // Start chip igxDrop behavior
808
    public onChipDragEnterHandler(event: IDropBaseEventArgs) {
UNCOV
809
        if (this.dragDirective === event.drag) {
×
810
            return;
×
811
        }
812

UNCOV
813
        const eventArgs: IChipEnterDragAreaEventArgs = {
×
814
            owner: this,
815
            dragChip: event.drag.data?.chip,
816
            originalEvent: event
817
        };
UNCOV
818
        this.dragEnter.emit(eventArgs);
×
819
    }
820

821
    /**
822
     * @hidden
823
     * @internal
824
     */
825
    public onChipDragLeaveHandler(event: IDropBaseEventArgs) {
UNCOV
826
        if (this.dragDirective === event.drag) {
×
827
            return;
×
828
        }
829

UNCOV
830
        const eventArgs: IChipEnterDragAreaEventArgs = {
×
831
            owner: this,
832
            dragChip: event.drag.data?.chip,
833
            originalEvent: event
834
        };
UNCOV
835
        this.dragLeave.emit(eventArgs);
×
836
    }
837

838
    /**
839
     * @hidden
840
     * @internal
841
     */
842
    public onChipDrop(event: IDropDroppedEventArgs) {
843
        // Cancel the default drop logic
UNCOV
844
        event.cancel = true;
×
UNCOV
845
        if (this.dragDirective === event.drag) {
×
846
            return;
×
847
        }
848

UNCOV
849
        const eventArgs: IChipEnterDragAreaEventArgs = {
×
850
            owner: this,
851
            dragChip: event.drag.data?.chip,
852
            originalEvent: event
853
        };
UNCOV
854
        this.dragDrop.emit(eventArgs);
×
855
    }
856

857
    /**
858
     * @hidden
859
     * @internal
860
     */
861
    public onChipOverHandler(event: IDropBaseEventArgs) {
UNCOV
862
        if (this.dragDirective === event.drag) {
×
863
            return;
×
864
        }
865

UNCOV
866
        const eventArgs: IChipEnterDragAreaEventArgs = {
×
867
            owner: this,
868
            dragChip: event.drag.data?.chip,
869
            originalEvent: event
870
        };
UNCOV
871
        this.dragOver.emit(eventArgs);
×
872
    }
873
    // End chip igxDrop behavior
874

875
    protected changeSelection(newValue: boolean, srcEvent = null) {
×
UNCOV
876
        const onSelectArgs: IChipSelectEventArgs = {
×
877
            originalEvent: srcEvent,
878
            owner: this,
879
            selected: false,
880
            cancel: false
881
        };
882

UNCOV
883
        if (newValue && !this._selected) {
×
UNCOV
884
            onSelectArgs.selected = true;
×
UNCOV
885
            this.selectedChanging.emit(onSelectArgs);
×
886

UNCOV
887
            if (!onSelectArgs.cancel) {
×
UNCOV
888
                this.renderer.addClass(this.chipArea.nativeElement, this._selectedItemClass);
×
UNCOV
889
                this._selected = newValue;
×
UNCOV
890
                this.selectedChange.emit(this._selected);
×
UNCOV
891
                this.selectedChanged.emit({
×
892
                    owner: this,
893
                    originalEvent: srcEvent
894
                });
895
            }
UNCOV
896
        } else if (!newValue && this._selected) {
×
UNCOV
897
            this.selectedChanging.emit(onSelectArgs);
×
898

UNCOV
899
            if (!onSelectArgs.cancel) {
×
UNCOV
900
                this.renderer.removeClass(this.chipArea.nativeElement, this._selectedItemClass);
×
UNCOV
901
                this._selected = newValue;
×
UNCOV
902
                this.selectedChange.emit(this._selected);
×
UNCOV
903
                this.selectedChanged.emit({
×
904
                    owner: this,
905
                    originalEvent: srcEvent
906
                });
907
            }
908
        }
909
    }
910

911
    public ngOnInit(): void {
912
        this.computedStyles = this.document.defaultView.getComputedStyle(this.nativeElement);
149✔
913
    }
914

915
    public ngOnDestroy(): void {
916
        this.destroy$.next();
149✔
917
        this.destroy$.complete();
149✔
918
    }
919
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc