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

IgniteUI / igniteui-angular / 15422972366

03 Jun 2025 04:41PM UTC coverage: 91.446%. Remained the same
15422972366

Pull #15882

github

web-flow
Merge f4c9a8334 into bb2802421
Pull Request #15882: refactor(*): replace mkenum with const assertion

13373 of 15684 branches covered (85.27%)

39 of 39 new or added lines in 24 files covered. (100.0%)

13 existing lines in 1 file now uncovered.

27004 of 29530 relevant lines covered (91.45%)

34152.0 hits per line

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

89.31
/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
    DOCUMENT
18
} from '@angular/core';
19
import { IgxDragDirective, IDragBaseEventArgs, IDragStartEventArgs, IDropBaseEventArgs, IDropDroppedEventArgs, IgxDropDirective } from '../directives/drag-drop/drag-drop.directive';
20
import { IBaseEventArgs } from '../core/utils';
21
import { ChipResourceStringsEN, IChipResourceStrings } from '../core/i18n/chip-resources';
22
import { Subject } from 'rxjs';
23
import { IgxIconComponent } from '../icon/icon.component';
24
import { NgClass, NgTemplateOutlet } from '@angular/common';
25
import { getCurrentResourceStrings } from '../core/i18n/resources';
26
import { Size } from '../grids/common/enums';
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

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

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

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

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

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

59
let CHIP_ID = 0;
3✔
60

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

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

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

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

142
    public get tabIndex() {
143
        if (this._tabIndex !== null) {
121,149✔
144
            return this._tabIndex;
39,359✔
145
        }
146
        return !this.disabled ? 0 : null;
81,790✔
147
    }
148

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

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

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

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

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

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

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

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

244
    /**
245
     * @hidden
246
     * @internal
247
     */
248
    @Input()
249
    public class = '';
6,824✔
250

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

490
    @HostBinding('class.igx-chip')
491
    protected defaultClass = 'igx-chip';
6,824✔
492

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

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

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

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

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

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

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

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

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

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

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

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

581
    /** @hidden @internal */
582
    public get nativeElement() {
583
        return this.ref.nativeElement;
21,248✔
584
    }
585

586
    /**
587
     * @hidden
588
     * @internal
589
     */
590
    public hideBaseElement = false;
6,824✔
591

592
    /**
593
     * @hidden
594
     * @internal
595
     */
596
    public destroy$ = new Subject<void>();
6,824✔
597

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

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

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

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

630
        return {
361✔
631
            [SELECT_CLASS]: condition,
632
            [`${SELECT_CLASS}--hidden`]: !condition
633
        };
634
    }
635

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

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

657
        this.keyDown.emit(keyDownArgs);
21✔
658
        if (keyDownArgs.cancel) {
21!
UNCOV
659
            return;
×
660
        }
661

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

669
        if ((event.key === ' ' || event.key === 'Spacebar') && this.selectable && !this.disabled) {
21✔
670
            this.changeSelection(!this.selected, event);
5✔
671
        }
672

673
        if (event.key !== 'Tab') {
21✔
674
            event.preventDefault();
21✔
675
        }
676
    }
677

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

689
            event.preventDefault();
4✔
690
            event.stopPropagation();
4✔
691
        }
692
    }
693

694
    public onRemoveMouseDown(event: PointerEvent | MouseEvent) {
695
        event.stopPropagation();
2✔
696
    }
697

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

884
        if (newValue && !this._selected) {
176✔
885
            onSelectArgs.selected = true;
105✔
886
            this.selectedChanging.emit(onSelectArgs);
105✔
887

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

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

912
    public ngOnInit(): void {
913
        this.computedStyles = this.document.defaultView.getComputedStyle(this.nativeElement);
6,824✔
914
    }
915

916
    public ngOnDestroy(): void {
917
        this.destroy$.next();
6,820✔
918
        this.destroy$.complete();
6,820✔
919
    }
920
}
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

© 2026 Coveralls, Inc