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

IgniteUI / igniteui-angular / 28358286454

29 Jun 2026 08:17AM UTC coverage: 90.127% (-0.05%) from 90.174%
28358286454

Pull #17246

github

web-flow
Merge 21687d939 into 07bdcd752
Pull Request #17246: fix(pivot-grid): fix date format based on the localization

14921 of 17392 branches covered (85.79%)

Branch coverage included in aggregate %.

29 of 32 new or added lines in 4 files covered. (90.63%)

735 existing lines in 76 files now uncovered.

29992 of 32441 relevant lines covered (92.45%)

34632.46 hits per line

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

87.57
/projects/igniteui-angular/chips/src/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
  DOCUMENT,
18
  ChangeDetectionStrategy
19
} from '@angular/core';
20
import { IgxDragDirective, IDragBaseEventArgs, IDragStartEventArgs, IDropBaseEventArgs, IDropDroppedEventArgs, IgxDropDirective } from 'igniteui-angular/directives';
21
import { IBaseEventArgs, ɵSize } from 'igniteui-angular/core';
22
import { ChipResourceStringsEN, IChipResourceStrings } from 'igniteui-angular/core';
23
import { Subject } from 'rxjs';
24
import { IgxIconComponent } from 'igniteui-angular/icon';
25
import { NgClass, NgTemplateOutlet } from '@angular/common';
26
import { getCurrentResourceStrings, onResourceChangeHandle } from 'igniteui-angular/core';
27

28
export const IgxChipTypeVariant = {
3✔
29
    PRIMARY: 'primary',
30
    INFO: 'info',
31
    SUCCESS: 'success',
32
    WARNING: 'warning',
33
    DANGER: 'danger'
34
} as const;
35
export type IgxChipTypeVariant = (typeof IgxChipTypeVariant)[keyof typeof IgxChipTypeVariant];
36

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

42
export interface IChipClickEventArgs extends IBaseChipEventArgs {
43
    cancel: boolean;
44
}
45

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

51
export interface IChipEnterDragAreaEventArgs extends IBaseChipEventArgs {
52
    dragChip: IgxChipComponent;
53
}
54

55
export interface IChipSelectEventArgs extends IBaseChipEventArgs {
56
    cancel: boolean;
57
    selected: boolean;
58
}
59

60
let CHIP_ID = 0;
3✔
61

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

97

98
    /**
99
     * Sets/gets the variant of the chip.
100
     *
101
     * @remarks
102
     * Allowed values are `primary`, `info`, `success`, `warning`, `danger`.
103
     * Providing no/nullish value leaves the chip in its default state.
104
     *
105
     * @example
106
     * ```html
107
     * <igx-chip variant="success"></igx-chip>
108
     * ```
109
     */
110
    @Input()
111
    public variant?: IgxChipTypeVariant | null;
112
    /**
113
     * Sets the value of `id` attribute. If not provided it will be automatically generated.
114
     *
115
     * @example
116
     * ```html
117
     * <igx-chip [id]="'igx-chip-1'"></igx-chip>
118
     * ```
119
     */
120
    @HostBinding('attr.id')
121
    @Input()
122
    public id = `igx-chip-${CHIP_ID++}`;
7,327✔
123

124
    /**
125
     * Returns the `role` attribute of the chip.
126
     *
127
     * @example
128
     * ```typescript
129
     * let chipRole = this.chip.role;
130
     * ```
131
     */
132
    @HostBinding('attr.role')
133
    public role = 'option';
7,327✔
134

135
    /**
136
     * Sets the value of `tabindex` attribute. If not provided it will use the element's tabindex if set.
137
     *
138
     * @example
139
     * ```html
140
     * <igx-chip [id]="'igx-chip-1'" [tabIndex]="1"></igx-chip>
141
     * ```
142
     */
143
    @HostBinding('attr.tabIndex')
144
    @Input()
145
    public set tabIndex(value: number) {
146
        this._tabIndex = value;
3,906✔
147
    }
148

149
    public get tabIndex() {
150
        if (this._tabIndex !== null) {
125,839✔
151
            return this._tabIndex;
39,687✔
152
        }
153
        return !this.disabled ? 0 : null;
86,152✔
154
    }
155

156
    /**
157
     * Stores data related to the chip.
158
     *
159
     * @example
160
     * ```html
161
     * <igx-chip [data]="{ value: 'Country' }"></igx-chip>
162
     * ```
163
     */
164
    @Input()
165
    public data: any;
166

167
    /**
168
     * Defines if the chip can be dragged in order to change it's position.
169
     * By default it is set to false.
170
     *
171
     * @example
172
     * ```html
173
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true"></igx-chip>
174
     * ```
175
     */
176
    @Input({ transform: booleanAttribute })
177
    public draggable = false;
7,327✔
178

179
    /**
180
     * Enables/disables the draggable element animation when the element is released.
181
     * By default it's set to true.
182
     *
183
     * @example
184
     * ```html
185
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true" [animateOnRelease]="false"></igx-chip>
186
     * ```
187
     */
188
    @Input({ transform: booleanAttribute })
189
    public animateOnRelease = true;
7,327✔
190

191
    /**
192
     * Enables/disables the hiding of the base element that has been dragged.
193
     * By default it's set to true.
194
     *
195
     * @example
196
     * ```html
197
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true" [hideBaseOnDrag]="false"></igx-chip>
198
     * ```
199
     */
200
    @Input({ transform: booleanAttribute })
201
    public hideBaseOnDrag = true;
7,327✔
202

203
    /**
204
     * Defines if the chip should render remove button and throw remove events.
205
     * By default it is set to false.
206
     *
207
     * @example
208
     * ```html
209
     * <igx-chip [id]="'igx-chip-1'" [draggable]="true" [removable]="true"></igx-chip>
210
     * ```
211
     */
212
    @Input({ transform: booleanAttribute })
213
    public removable = false;
7,327✔
214

215
    /**
216
     * Overrides the default icon that the chip applies to the remove button.
217
     *
218
     * @example
219
     * ```html
220
     * <igx-chip [id]="chip.id" [removable]="true" [removeIcon]="iconTemplate"></igx-chip>
221
     * <ng-template #iconTemplate><igx-icon>delete</igx-icon></ng-template>
222
     * ```
223
     */
224
    @Input()
225
    public removeIcon: TemplateRef<any>;
226

227
    /**
228
     * Defines if the chip can be selected on click or through navigation,
229
     * By default it is set to false.
230
     *
231
     * @example
232
     * ```html
233
     * <igx-chip [id]="chip.id" [draggable]="true" [removable]="true" [selectable]="true"></igx-chip>
234
     * ```
235
     */
236
    @Input({ transform: booleanAttribute })
237
    public selectable = false;
7,327✔
238

239
    /**
240
     * Overrides the default icon that the chip applies when it is selected.
241
     *
242
     * @example
243
     * ```html
244
     * <igx-chip [id]="chip.id" [selectable]="true" [selectIcon]="iconTemplate"></igx-chip>
245
     * <ng-template #iconTemplate><igx-icon>done_outline</igx-icon></ng-template>
246
     * ```
247
     */
248
    @Input()
249
    public selectIcon: TemplateRef<any>;
250

251
    /**
252
     * @hidden
253
     * @internal
254
     */
255
    @Input()
256
    public class = '';
7,327✔
257

258
    /**
259
     * Disables the chip. When disabled it restricts user interactions
260
     * like focusing on click or tab, selection on click or Space, dragging.
261
     * By default it is set to false.
262
     *
263
     * @example
264
     * ```html
265
     * <igx-chip [id]="chip.id" [disabled]="true"></igx-chip>
266
     * ```
267
     */
268
    @HostBinding('class.igx-chip--disabled')
269
    @Input({ transform: booleanAttribute })
270
    public disabled = false;
7,327✔
271

272
    /**
273
     * Sets the chip selected state.
274
     *
275
     * @example
276
     * ```html
277
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" [selected]="true">
278
     * ```
279
     *
280
     * Two-way data binding:
281
     * ```html
282
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" [(selected)]="model.isSelected">
283
     * ```
284
     */
285
    @HostBinding('attr.aria-selected')
286
    @Input({ transform: booleanAttribute })
287
    public set selected(newValue: boolean) {
288
        this.changeSelection(newValue);
169✔
289
    }
290

291
    /**
292
     * Returns if the chip is selected.
293
     *
294
     * @example
295
     * ```typescript
296
     * @ViewChild('myChip')
297
     * public chip: IgxChipComponent;
298
     * selectedChip(){
299
     *     let selectedChip = this.chip.selected;
300
     * }
301
     * ```
302
     */
303
    public get selected() {
304
        return this._selected;
195,431✔
305
    }
306

307
    /**
308
     * @hidden
309
     * @internal
310
     */
311
    @Output()
312
    public selectedChange = new EventEmitter<boolean>();
7,327✔
313

314
    /**
315
     * Sets the chip background color.
316
     * The `color` property supports string, rgb, hex.
317
     *
318
     * @example
319
     * ```html
320
     * <igx-chip #myChip [id]="'igx-chip-1'" [color]="'#ff0000'"></igx-chip>
321
     * ```
322
     */
323
    @Input()
324
    public set color(newColor) {
325
        this.chipArea.nativeElement.style.backgroundColor = newColor;
1✔
326
    }
327

328
    /**
329
     * Returns the background color of the chip.
330
     *
331
     * @example
332
     * ```typescript
333
     * @ViewChild('myChip')
334
     * public chip: IgxChipComponent;
335
     * ngAfterViewInit(){
336
     *     let chipColor = this.chip.color;
337
     * }
338
     * ```
339
     */
340
    public get color() {
341
        return this.chipArea.nativeElement.style.backgroundColor;
1✔
342
    }
343

344
    /**
345
     * An accessor that sets the resource strings.
346
     * By default it uses EN resources.
347
     */
348
    @Input()
349
    public set resourceStrings(value: IChipResourceStrings) {
UNCOV
350
        this._resourceStrings = Object.assign({}, this._resourceStrings, value);
×
351
    }
352

353
    /**
354
     * An accessor that returns the resource strings.
355
     */
356
    public get resourceStrings(): IChipResourceStrings {
357
        return this._resourceStrings || this._defaultResourceStrings;
31,354✔
358
    }
359

360
    /**
361
     * Emits an event when the chip moving starts.
362
     * Returns the moving chip.
363
     *
364
     * @example
365
     * ```html
366
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (moveStart)="moveStarted($event)">
367
     * ```
368
     */
369
    @Output()
370
    public moveStart = new EventEmitter<IBaseChipEventArgs>();
7,327✔
371

372
    /**
373
     * Emits an event when the chip moving ends.
374
     * Returns the moved chip.
375
     *
376
     * @example
377
     * ```html
378
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (moveEnd)="moveEnded($event)">
379
     * ```
380
     */
381
    @Output()
382
    public moveEnd = new EventEmitter<IBaseChipEventArgs>();
7,327✔
383

384
    /**
385
     * Emits an event when the chip is removed.
386
     * Returns the removed chip.
387
     *
388
     * @example
389
     * ```html
390
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (remove)="remove($event)">
391
     * ```
392
     */
393
    @Output()
394
    public remove = new EventEmitter<IBaseChipEventArgs>();
7,327✔
395

396
    /**
397
     * Emits an event when the chip is clicked.
398
     * Returns the clicked chip, whether the event should be canceled.
399
     *
400
     * @example
401
     * ```html
402
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (click)="chipClick($event)">
403
     * ```
404
     */
405
    @Output()
406
    public chipClick = new EventEmitter<IChipClickEventArgs>();
7,327✔
407

408
    /**
409
     * Emits event when the chip is selected/deselected.
410
     * Returns the selected chip reference, whether the event should be canceled, what is the next selection state and
411
     * when the event is triggered by interaction `originalEvent` is provided, otherwise `originalEvent` is `null`.
412
     *
413
     * @example
414
     * ```html
415
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" (selectedChanging)="chipSelect($event)">
416
     * ```
417
     */
418
    @Output()
419
    public selectedChanging = new EventEmitter<IChipSelectEventArgs>();
7,327✔
420

421
    /**
422
     * Emits event when the chip is selected/deselected and any related animations and transitions also end.
423
     *
424
     * @example
425
     * ```html
426
     * <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" (selectedChanged)="chipSelectEnd($event)">
427
     * ```
428
     */
429
    @Output()
430
    public selectedChanged = new EventEmitter<IBaseChipEventArgs>();
7,327✔
431

432
    /**
433
     * Emits an event when the chip keyboard navigation is being used.
434
     * Returns the focused/selected chip, whether the event should be canceled,
435
     * if the `alt`, `shift` or `control` key is pressed and the pressed key name.
436
     *
437
     * @example
438
     * ```html
439
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (keyDown)="chipKeyDown($event)">
440
     * ```
441
     */
442
    @Output()
443
    public keyDown = new EventEmitter<IChipKeyDownEventArgs>();
7,327✔
444

445
    /**
446
     * Emits an event when the chip has entered the chips area.
447
     * Returns the target chip, the drag chip, as  well as
448
     * the original drop event arguments.
449
     *
450
     * @example
451
     * ```html
452
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragEnter)="chipEnter($event)">
453
     * ```
454
     */
455
    @Output()
456
    public dragEnter = new EventEmitter<IChipEnterDragAreaEventArgs>();
7,327✔
457

458
    /**
459
     * Emits an event when the chip has left the chips area.
460
     * Returns the target chip, the drag chip, as  well as
461
     * the original drop event arguments.
462
     *
463
     * @example
464
     * ```html
465
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragLeave)="chipLeave($event)">
466
     * ```
467
     */
468
    @Output()
469
    public dragLeave = new EventEmitter<IChipEnterDragAreaEventArgs>();
7,327✔
470

471
    /**
472
     * Emits an event when the chip is over the chips area.
473
     * Returns the target chip, the drag chip, as  well as
474
     * the original drop event arguments.
475
     *
476
     * @example
477
     * ```html
478
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragOver)="chipOver($event)">
479
     * ```
480
     */
481
    @Output()
482
    public dragOver = new EventEmitter<IChipEnterDragAreaEventArgs>();
7,327✔
483

484
    /**
485
     * Emits an event when the chip has been dropped in the chips area.
486
     * Returns the target chip, the drag chip, as  well as
487
     * the original drop event arguments.
488
     *
489
     * @example
490
     * ```html
491
     * <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (dragDrop)="chipLeave($event)">
492
     * ```
493
     */
494
    @Output()
495
    public dragDrop = new EventEmitter<IChipEnterDragAreaEventArgs>();
7,327✔
496

497
    @HostBinding('class.igx-chip')
498
    protected defaultClass = 'igx-chip';
7,327✔
499

500
    @HostBinding('class.igx-chip--primary')
501
    protected get isPrimary() {
502
        return this.variant === IgxChipTypeVariant.PRIMARY;
94,836✔
503
    }
504

505
    @HostBinding('class.igx-chip--info')
506
    protected get isInfo() {
507
        return this.variant === IgxChipTypeVariant.INFO;
94,836✔
508
    }
509

510
    @HostBinding('class.igx-chip--success')
511
    protected get isSuccess() {
512
        return this.variant === IgxChipTypeVariant.SUCCESS;
94,836✔
513
    }
514

515
    @HostBinding('class.igx-chip--warning')
516
    protected get isWarning() {
517
        return this.variant === IgxChipTypeVariant.WARNING;
94,836✔
518
    }
519

520
    @HostBinding('class.igx-chip--danger')
521
    protected get isDanger() {
522
        return this.variant === IgxChipTypeVariant.DANGER;
94,836✔
523
    }
524

525
    /**
526
     * Property that contains a reference to the drag the chip uses for dragging behavior.
527
     *
528
     * @example
529
     * ```html
530
     * <igx-chip [id]="chip.id" [draggable]="true"></igx-chip>
531
     * ```
532
     * ```typescript
533
     * onMoveStart(event: IBaseChipEventArgs){
534
     *     let dragDirective = event.owner.dragDirective;
535
     * }
536
     * ```
537
     */
538
    @ViewChild('chipArea', { read: IgxDragDirective, static: true })
539
    public dragDirective: IgxDragDirective;
540

541
    /**
542
     * @hidden
543
     * @internal
544
     */
545
    @ViewChild('chipArea', { read: ElementRef, static: true })
546
    public chipArea: ElementRef;
547

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

555
    /**
556
     * @hidden
557
     * @internal
558
     */
559
    @ViewChild('defaultSelectIcon', { read: TemplateRef, static: true })
560
    public defaultSelectIcon: TemplateRef<any>;
561

562
    /**
563
     * @hidden
564
     * @internal
565
     */
566
    public get removeButtonTemplate() {
567
        if (!this.disabled) {
31,003✔
568
            return this.removeIcon || this.defaultRemoveIcon;
31,003✔
569
        }
570
    }
571

572
    /**
573
     * @hidden
574
     * @internal
575
     */
576
    public get selectIconTemplate() {
577
        return this.selectIcon || this.defaultSelectIcon;
351✔
578
    }
579

580
    /**
581
     * @hidden
582
     * @internal
583
     */
584
    public get ghostStyles() {
585
        return { '--ig-size': `${this.chipSize}` };
94,869✔
586
    }
587

588
    /** @hidden @internal */
589
    public get nativeElement() {
590
        return this.ref.nativeElement;
23,876✔
591
    }
592

593
    /**
594
     * @hidden
595
     * @internal
596
     */
597
    public hideBaseElement = false;
7,327✔
598

599
    /**
600
     * @hidden
601
     * @internal
602
     */
603
    public destroy$ = new Subject<void>();
7,327✔
604

605
    protected get chipSize(): ɵSize {
606
        return this.computedStyles?.getPropertyValue('--ig-size') || ɵSize.Medium;
94,869✔
607
    }
608
    protected _tabIndex = null;
7,327✔
609
    protected _selected = false;
7,327✔
610
    protected _selectedItemClass = 'igx-chip__item--selected';
7,327✔
611
    protected _movedWhileRemoving = false;
7,327✔
612
    protected computedStyles;
613
    private _resourceStrings: IChipResourceStrings = null;
7,327✔
614
    private _defaultResourceStrings = getCurrentResourceStrings(ChipResourceStringsEN);
7,327✔
615

616
    constructor() {
617
        onResourceChangeHandle(this.destroy$, () => {
7,327✔
618
            this._defaultResourceStrings = getCurrentResourceStrings(ChipResourceStringsEN, false);
43✔
619
        }, this);
620
    }
621

622
    /**
623
     * @hidden
624
     * @internal
625
     */
626
    @HostListener('keydown', ['$event'])
627
    public keyEvent(event: KeyboardEvent) {
628
        this.onChipKeyDown(event);
10✔
629
    }
630

631
    /**
632
     * @hidden
633
     * @internal
634
     */
635
    public selectClass(condition: boolean): any {
636
        const SELECT_CLASS = 'igx-chip__select';
351✔
637

638
        return {
351✔
639
            [SELECT_CLASS]: condition,
640
            [`${SELECT_CLASS}--hidden`]: !condition
641
        };
642
    }
643

644
    public onSelectTransitionDone(event) {
645
        if (event.target.tagName) {
×
646
            // Trigger onSelectionDone on when `width` property is changed and the target is valid element(not comment).
UNCOV
647
            this.selectedChanged.emit({
×
648
                owner: this,
649
                originalEvent: event
650
            });
651
        }
652
    }
653

654
    /**
655
     * @hidden
656
     * @internal
657
     */
658
    public onChipKeyDown(event: KeyboardEvent) {
659
        const keyDownArgs: IChipKeyDownEventArgs = {
21✔
660
            originalEvent: event,
661
            owner: this,
662
            cancel: false
663
        };
664

665
        this.keyDown.emit(keyDownArgs);
21✔
666
        if (keyDownArgs.cancel) {
21!
UNCOV
667
            return;
×
668
        }
669

670
        if ((event.key === 'Delete' || event.key === 'Del') && this.removable) {
21✔
671
            this.remove.emit({
3✔
672
                originalEvent: event,
673
                owner: this
674
            });
675
        }
676

677
        if ((event.key === ' ' || event.key === 'Spacebar') && this.selectable && !this.disabled) {
21✔
678
            this.changeSelection(!this.selected, event);
5✔
679
        }
680

681
        if (event.key !== 'Tab') {
21✔
682
            event.preventDefault();
21✔
683
        }
684
    }
685

686
    /**
687
     * @hidden
688
     * @internal
689
     */
690
    public onRemoveBtnKeyDown(event: KeyboardEvent) {
691
        if (event.key === ' ' || event.key === 'Spacebar' || event.key === 'Enter') {
4✔
692
            this.remove.emit({
4✔
693
                originalEvent: event,
694
                owner: this
695
            });
696

697
            event.preventDefault();
4✔
698
            event.stopPropagation();
4✔
699
        }
700
    }
701

702
    public onRemoveMouseDown(event: PointerEvent | MouseEvent) {
703
        event.stopPropagation();
2✔
704
    }
705

706
    /**
707
     * @hidden
708
     * @internal
709
     */
710
    public onRemoveClick(event: MouseEvent | TouchEvent) {
711
        this.remove.emit({
26✔
712
            originalEvent: event,
713
            owner: this
714
        });
715
    }
716

717
    /**
718
     * @hidden
719
     * @internal
720
     */
721
    public onRemoveTouchMove() {
722
        // We don't remove chip if user starting touch interacting on the remove button moves the chip
UNCOV
723
        this._movedWhileRemoving = true;
×
724
    }
725

726
    /**
727
     * @hidden
728
     * @internal
729
     */
730
    public onRemoveTouchEnd(event: TouchEvent) {
UNCOV
731
        if (!this._movedWhileRemoving) {
×
732
            this.onRemoveClick(event);
×
733
        }
UNCOV
734
        this._movedWhileRemoving = false;
×
735
    }
736

737
    /**
738
     * @hidden
739
     * @internal
740
     */
741
    // -----------------------------
742
    // Start chip igxDrag behavior
743
    public onChipDragStart(event: IDragStartEventArgs) {
744
        this.moveStart.emit({
35✔
745
            originalEvent: event,
746
            owner: this
747
        });
748
        event.cancel = !this.draggable || this.disabled;
35✔
749
    }
750

751
    /**
752
     * @hidden
753
     * @internal
754
     */
755
    public onChipDragEnd() {
756
        if (this.animateOnRelease) {
13!
UNCOV
757
            this.dragDirective.transitionToOrigin();
×
758
        }
759
    }
760

761
    /**
762
     * @hidden
763
     * @internal
764
     */
765
    public onChipMoveEnd(event: IDragBaseEventArgs) {
766
        // moveEnd is triggered after return animation has finished. This happen when we drag and release the chip.
767
        this.moveEnd.emit({
13✔
768
            originalEvent: event,
769
            owner: this
770
        });
771

772
        if (this.selected) {
13!
UNCOV
773
            this.chipArea.nativeElement.focus();
×
774
        }
775
    }
776

777
    /**
778
     * @hidden
779
     * @internal
780
     */
781
    public onChipGhostCreate() {
782
        this.hideBaseElement = this.hideBaseOnDrag;
33✔
783
    }
784

785
    /**
786
     * @hidden
787
     * @internal
788
     */
789
    public onChipGhostDestroy() {
790
        this.hideBaseElement = false;
13✔
791
    }
792

793
    /**
794
     * @hidden
795
     * @internal
796
     */
797
    public onChipDragClicked(event: IDragBaseEventArgs) {
798
        const clickEventArgs: IChipClickEventArgs = {
4✔
799
            originalEvent: event,
800
            owner: this,
801
            cancel: false
802
        };
803
        this.chipClick.emit(clickEventArgs);
4✔
804

805
        if (!clickEventArgs.cancel && this.selectable && !this.disabled) {
4✔
806
            this.changeSelection(!this.selected, event);
2✔
807
        }
808
    }
809
    // End chip igxDrag behavior
810

811
    /**
812
     * @hidden
813
     * @internal
814
     */
815
    // -----------------------------
816
    // Start chip igxDrop behavior
817
    public onChipDragEnterHandler(event: IDropBaseEventArgs) {
818
        if (this.dragDirective === event.drag) {
42!
UNCOV
819
            return;
×
820
        }
821

822
        const eventArgs: IChipEnterDragAreaEventArgs = {
42✔
823
            owner: this,
824
            dragChip: event.drag.data?.chip,
825
            originalEvent: event
826
        };
827
        this.dragEnter.emit(eventArgs);
42✔
828
    }
829

830
    /**
831
     * @hidden
832
     * @internal
833
     */
834
    public onChipDragLeaveHandler(event: IDropBaseEventArgs) {
835
        if (this.dragDirective === event.drag) {
34!
UNCOV
836
            return;
×
837
        }
838

839
        const eventArgs: IChipEnterDragAreaEventArgs = {
34✔
840
            owner: this,
841
            dragChip: event.drag.data?.chip,
842
            originalEvent: event
843
        };
844
        this.dragLeave.emit(eventArgs);
34✔
845
    }
846

847
    /**
848
     * @hidden
849
     * @internal
850
     */
851
    public onChipDrop(event: IDropDroppedEventArgs) {
852
        // Cancel the default drop logic
853
        event.cancel = true;
9✔
854
        if (this.dragDirective === event.drag) {
9!
UNCOV
855
            return;
×
856
        }
857

858
        const eventArgs: IChipEnterDragAreaEventArgs = {
9✔
859
            owner: this,
860
            dragChip: event.drag.data?.chip,
861
            originalEvent: event
862
        };
863
        this.dragDrop.emit(eventArgs);
9✔
864
    }
865

866
    /**
867
     * @hidden
868
     * @internal
869
     */
870
    public onChipOverHandler(event: IDropBaseEventArgs) {
871
        if (this.dragDirective === event.drag) {
304!
UNCOV
872
            return;
×
873
        }
874

875
        const eventArgs: IChipEnterDragAreaEventArgs = {
304✔
876
            owner: this,
877
            dragChip: event.drag.data?.chip,
878
            originalEvent: event
879
        };
880
        this.dragOver.emit(eventArgs);
304✔
881
    }
882
    // End chip igxDrop behavior
883

884
    protected changeSelection(newValue: boolean, srcEvent = null) {
169✔
885
        const onSelectArgs: IChipSelectEventArgs = {
176✔
886
            originalEvent: srcEvent,
887
            owner: this,
888
            selected: false,
889
            cancel: false
890
        };
891

892
        if (newValue && !this._selected) {
176✔
893
            onSelectArgs.selected = true;
105✔
894
            this.selectedChanging.emit(onSelectArgs);
105✔
895

896
            if (!onSelectArgs.cancel) {
105✔
897
                this.renderer.addClass(this.chipArea.nativeElement, this._selectedItemClass);
105✔
898
                this._selected = newValue;
105✔
899
                this.selectedChange.emit(this._selected);
105✔
900
                this.selectedChanged.emit({
105✔
901
                    owner: this,
902
                    originalEvent: srcEvent
903
                });
904
            }
905
        } else if (!newValue && this._selected) {
71✔
906
            this.selectedChanging.emit(onSelectArgs);
30✔
907

908
            if (!onSelectArgs.cancel) {
30✔
909
                this.renderer.removeClass(this.chipArea.nativeElement, this._selectedItemClass);
30✔
910
                this._selected = newValue;
30✔
911
                this.selectedChange.emit(this._selected);
30✔
912
                this.selectedChanged.emit({
30✔
913
                    owner: this,
914
                    originalEvent: srcEvent
915
                });
916
            }
917
        }
918
    }
919

920
    public ngOnInit(): void {
921
        this.computedStyles = this.document.defaultView.getComputedStyle(this.nativeElement);
7,327✔
922
    }
923

924
    public ngOnDestroy(): void {
925
        this.destroy$.next();
7,325✔
926
        this.destroy$.complete();
7,325✔
927
    }
928
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc