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

IgniteUI / igniteui-angular / 16053471080

03 Jul 2025 02:41PM UTC coverage: 4.981% (-86.4%) from 91.409%
16053471080

Pull #16021

github

web-flow
Merge 7c49966eb into 7e40671a1
Pull Request #16021: fix(radio-group): dynamically added radio buttons do not initialize

178 of 15753 branches covered (1.13%)

13 of 14 new or added lines in 2 files covered. (92.86%)

25644 existing lines in 324 files now uncovered.

1478 of 29670 relevant lines covered (4.98%)

0.51 hits per line

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

2.29
/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
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
    imports: [IgxDropDirective, IgxDragDirective, NgClass, NgTemplateOutlet, IgxIconComponent]
89
})
90
export class IgxChipComponent implements OnInit, OnDestroy {
3✔
91

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

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

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

143
    public get tabIndex() {
UNCOV
144
        if (this._tabIndex !== null) {
×
UNCOV
145
            return this._tabIndex;
×
146
        }
UNCOV
147
        return !this.disabled ? 0 : null;
×
148
    }
149

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

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

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

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

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

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

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

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

245
    /**
246
     * @hidden
247
     * @internal
248
     */
249
    @Input()
UNCOV
250
    public class = '';
×
251

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

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

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

301
    /**
302
     * @hidden
303
     * @internal
304
     */
305
    @Output()
UNCOV
306
    public selectedChange = new EventEmitter<boolean>();
×
307

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

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

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

347
    /**
348
     * An accessor that returns the resource strings.
349
     */
350
    public get resourceStrings(): IChipResourceStrings {
UNCOV
351
        return this._resourceStrings;
×
352
    }
353

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

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

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

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

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

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

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

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

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

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

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

491
    @HostBinding('class.igx-chip')
UNCOV
492
    protected defaultClass = 'igx-chip';
×
493

494
    @HostBinding('class.igx-chip--primary')
495
    protected get isPrimary() {
UNCOV
496
        return this.variant === IgxChipTypeVariant.PRIMARY;
×
497
    }
498

499
    @HostBinding('class.igx-chip--info')
500
    protected get isInfo() {
UNCOV
501
        return this.variant === IgxChipTypeVariant.INFO;
×
502
    }
503

504
    @HostBinding('class.igx-chip--success')
505
    protected get isSuccess() {
UNCOV
506
        return this.variant === IgxChipTypeVariant.SUCCESS;
×
507
    }
508

509
    @HostBinding('class.igx-chip--warning')
510
    protected get isWarning() {
UNCOV
511
        return this.variant === IgxChipTypeVariant.WARNING;
×
512
    }
513

514
    @HostBinding('class.igx-chip--danger')
515
    protected get isDanger() {
UNCOV
516
        return this.variant === IgxChipTypeVariant.DANGER;
×
517
    }
518

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

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

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

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

556
    /**
557
     * @hidden
558
     * @internal
559
     */
560
    public get removeButtonTemplate() {
UNCOV
561
        if (!this.disabled) {
×
UNCOV
562
            return this.removeIcon || this.defaultRemoveIcon;
×
563
        }
564
    }
565

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

574
    /**
575
     * @hidden
576
     * @internal
577
     */
578
    public get ghostStyles() {
UNCOV
579
        return { '--ig-size': `${this.chipSize}` };
×
580
    }
581

582
    /** @hidden @internal */
583
    public get nativeElement() {
UNCOV
584
        return this.ref.nativeElement;
×
585
    }
586

587
    /**
588
     * @hidden
589
     * @internal
590
     */
UNCOV
591
    public hideBaseElement = false;
×
592

593
    /**
594
     * @hidden
595
     * @internal
596
     */
UNCOV
597
    public destroy$ = new Subject<void>();
×
598

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
690
            event.preventDefault();
×
UNCOV
691
            event.stopPropagation();
×
692
        }
693
    }
694

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

913
    public ngOnInit(): void {
UNCOV
914
        this.computedStyles = this.document.defaultView.getComputedStyle(this.nativeElement);
×
915
    }
916

917
    public ngOnDestroy(): void {
UNCOV
918
        this.destroy$.next();
×
UNCOV
919
        this.destroy$.complete();
×
920
    }
921
}
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