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

IgniteUI / igniteui-angular / 29587398373

17 Jul 2026 02:17PM UTC coverage: 90.116% (-0.02%) from 90.135%
29587398373

Pull #15125

github

web-flow
Merge ac93ee972 into 8ebabbb38
Pull Request #15125: refactor(*): bundle styles with components

14920 of 17397 branches covered (85.76%)

Branch coverage included in aggregate %.

30030 of 32483 relevant lines covered (92.45%)

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

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

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

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

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

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

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

61
let CHIP_ID = 0;
3✔
62

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

100

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

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

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

152
    public get tabIndex() {
153
        if (this._tabIndex !== null) {
125,758✔
154
            return this._tabIndex;
39,700✔
155
        }
156
        return !this.disabled ? 0 : null;
86,058✔
157
    }
158

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

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

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

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

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

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

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

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

254
    /**
255
     * @hidden
256
     * @internal
257
     */
258
    @Input()
259
    public class = '';
7,313✔
260

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

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

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

310
    /**
311
     * @hidden
312
     * @internal
313
     */
314
    @Output()
315
    public selectedChange = new EventEmitter<boolean>();
7,313✔
316

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

500
    @HostBinding('class.igx-chip')
501
    protected defaultClass = 'igx-chip';
7,313✔
502

503
    @HostBinding('class.igx-chip--primary')
504
    protected get isPrimary() {
505
        return this.variant === IgxChipTypeVariant.PRIMARY;
94,769✔
506
    }
507

508
    @HostBinding('class.igx-chip--info')
509
    protected get isInfo() {
510
        return this.variant === IgxChipTypeVariant.INFO;
94,769✔
511
    }
512

513
    @HostBinding('class.igx-chip--success')
514
    protected get isSuccess() {
515
        return this.variant === IgxChipTypeVariant.SUCCESS;
94,769✔
516
    }
517

518
    @HostBinding('class.igx-chip--warning')
519
    protected get isWarning() {
520
        return this.variant === IgxChipTypeVariant.WARNING;
94,769✔
521
    }
522

523
    @HostBinding('class.igx-chip--danger')
524
    protected get isDanger() {
525
        return this.variant === IgxChipTypeVariant.DANGER;
94,769✔
526
    }
527

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

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

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

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

565
    /**
566
     * @hidden
567
     * @internal
568
     */
569
    public get removeButtonTemplate() {
570
        if (!this.disabled) {
30,989✔
571
            return this.removeIcon || this.defaultRemoveIcon;
30,989✔
572
        }
573
    }
574

575
    /**
576
     * @hidden
577
     * @internal
578
     */
579
    public get selectIconTemplate() {
580
        return this.selectIcon || this.defaultSelectIcon;
357✔
581
    }
582

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

591
    /** @hidden @internal */
592
    public get nativeElement() {
593
        return this.ref.nativeElement;
23,803✔
594
    }
595

596
    /**
597
     * @hidden
598
     * @internal
599
     */
600
    public hideBaseElement = false;
7,313✔
601

602
    /**
603
     * @hidden
604
     * @internal
605
     */
606
    public destroy$ = new Subject<void>();
7,313✔
607

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

619
    constructor() {
620
        onResourceChangeHandle(this.destroy$, () => {
7,313✔
621
            this._defaultResourceStrings = getCurrentResourceStrings(ChipResourceStringsEN, false);
43✔
622
        }, this);
623
    }
624

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

634
    /**
635
     * @hidden
636
     * @internal
637
     */
638
    public selectClass(condition: boolean): any {
639
        const SELECT_CLASS = 'igx-chip__select';
357✔
640

641
        return {
357✔
642
            [SELECT_CLASS]: condition,
643
            [`${SELECT_CLASS}--hidden`]: !condition
644
        };
645
    }
646

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

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

668
        this.keyDown.emit(keyDownArgs);
21✔
669
        if (keyDownArgs.cancel) {
21!
670
            return;
×
671
        }
672

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

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

684
        if (event.key !== 'Tab') {
21✔
685
            event.preventDefault();
21✔
686
        }
687
    }
688

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

700
            event.preventDefault();
4✔
701
            event.stopPropagation();
4✔
702
        }
703
    }
704

705
    public onRemoveMouseDown(event: PointerEvent | MouseEvent) {
706
        event.stopPropagation();
2✔
707
    }
708

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

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

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

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

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

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

775
        if (this.selected) {
13!
776
            this.chipArea.nativeElement.focus();
×
777
        }
778
    }
779

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

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

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

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

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

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

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

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

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

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

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

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

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

895
        if (newValue && !this._selected) {
176✔
896
            onSelectArgs.selected = true;
105✔
897
            this.selectedChanging.emit(onSelectArgs);
105✔
898

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

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

923
    public ngOnInit(): void {
924
        this.computedStyles = this.document.defaultView.getComputedStyle(this.nativeElement);
7,313✔
925
    }
926

927
    public ngOnDestroy(): void {
928
        this.destroy$.next();
7,311✔
929
        this.destroy$.complete();
7,311✔
930
    }
931
}
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