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

IgniteUI / igniteui-angular / 15928253068

27 Jun 2025 02:06PM UTC coverage: 91.49% (+0.09%) from 91.402%
15928253068

Pull #15982

github

web-flow
Merge a5c8d7335 into 9953ebd3e
Pull Request #15982: Address grids column headers accessibility issues - active descendant, what is announced by SRs

13447 of 15767 branches covered (85.29%)

31 of 32 new or added lines in 8 files covered. (96.88%)

18 existing lines in 1 file now uncovered.

27134 of 29658 relevant lines covered (91.49%)

39322.95 hits per line

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

91.72
/projects/igniteui-angular/src/lib/grids/cell.component.ts
1
import {
2
    ChangeDetectionStrategy,
3
    ChangeDetectorRef,
4
    Component,
5
    ElementRef,
6
    HostBinding,
7
    HostListener,
8
    Input,
9
    TemplateRef,
10
    ViewChild,
11
    NgZone,
12
    OnInit,
13
    OnDestroy,
14
    OnChanges,
15
    SimpleChanges,
16
    Inject,
17
    ViewChildren,
18
    QueryList,
19
    AfterViewInit,
20
    booleanAttribute
21
} from '@angular/core';
22
import { formatPercent, NgClass, NgTemplateOutlet, DecimalPipe, PercentPipe, CurrencyPipe, DatePipe, getLocaleCurrencyCode, getCurrencySymbol } from '@angular/common';
23
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
24

25
import { first, takeUntil, takeWhile } from 'rxjs/operators';
26
import { Subject } from 'rxjs';
27

28
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive';
29
import { formatCurrency, formatDate, PlatformUtil } from '../core/utils';
30
import { IgxGridSelectionService } from './selection/selection.service';
31
import { HammerGesturesManager } from '../core/touch';
32
import { GridSelectionMode } from './common/enums';
33
import { CellType, ColumnType, GridType, IgxCellTemplateContext, IGX_GRID_BASE, RowType } from './common/grid.interface';
34
import { GridColumnDataType } from '../data-operations/data-util';
35
import { IgxRowDirective } from './row.directive';
36
import { ISearchInfo } from './common/events';
37
import { IgxGridCell } from './grid-public-cell';
38
import { ISelectionNode } from './common/types';
39
import { AutoPositionStrategy, HorizontalAlignment, IgxOverlayService } from '../services/public_api';
40
import { IgxIconComponent } from '../icon/icon.component';
41
import { IgxGridCellImageAltPipe, IgxStringReplacePipe, IgxColumnFormatterPipe } from './common/pipes';
42
import { IgxTooltipDirective } from '../directives/tooltip/tooltip.directive';
43
import { IgxTooltipTargetDirective } from '../directives/tooltip/tooltip-target.directive';
44
import { IgxSuffixDirective } from '../directives/suffix/suffix.directive';
45
import { IgxPrefixDirective } from '../directives/prefix/prefix.directive';
46
import { IgxDateTimeEditorDirective } from '../directives/date-time-editor/date-time-editor.directive';
47
import { IgxTimePickerComponent } from '../time-picker/time-picker.component';
48
import { IgxDatePickerComponent } from '../date-picker/date-picker.component';
49
import { IgxCheckboxComponent } from '../checkbox/checkbox.component';
50
import { IgxTextSelectionDirective } from '../directives/text-selection/text-selection.directive';
51
import { IgxFocusDirective } from '../directives/focus/focus.directive';
52
import { IgxInputDirective } from '../directives/input/input.directive';
53
import { IgxInputGroupComponent } from '../input-group/input-group.component';
54
import { IgxChipComponent } from '../chips/chip.component';
55

56
/**
57
 * Providing reference to `IgxGridCellComponent`:
58
 * ```typescript
59
 * @ViewChild('grid', { read: IgxGridComponent })
60
 *  public grid: IgxGridComponent;
61
 * ```
62
 * ```typescript
63
 *  let column = this.grid.columnList.first;
64
 * ```
65
 * ```typescript
66
 *  let cell = column.cells[0];
67
 * ```
68
 */
69
@Component({
70
    changeDetection: ChangeDetectionStrategy.OnPush,
71
    selector: 'igx-grid-cell',
72
    templateUrl: './cell.component.html',
73
    providers: [HammerGesturesManager],
74
    imports: [
75
        NgClass,
76
        NgTemplateOutlet,
77
        DecimalPipe,
78
        PercentPipe,
79
        CurrencyPipe,
80
        DatePipe,
81
        ReactiveFormsModule,
82
        IgxChipComponent,
83
        IgxTextHighlightDirective,
84
        IgxIconComponent,
85
        IgxInputGroupComponent,
86
        IgxInputDirective,
87
        IgxFocusDirective,
88
        IgxTextSelectionDirective,
89
        IgxCheckboxComponent,
90
        IgxDatePickerComponent,
91
        IgxTimePickerComponent,
92
        IgxDateTimeEditorDirective,
93
        IgxPrefixDirective,
94
        IgxSuffixDirective,
95
        IgxTooltipTargetDirective,
96
        IgxTooltipDirective,
97
        IgxGridCellImageAltPipe,
98
        IgxStringReplacePipe,
99
        IgxColumnFormatterPipe
100
    ]
101
})
102
export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellType, AfterViewInit {
3✔
103
    private _destroy$ = new Subject<void>();
152,198✔
104
    /**
105
     * @hidden
106
     * @internal
107
     */
108
    @HostBinding('class.igx-grid__td--new')
109
    public get isEmptyAddRowCell() {
110
        return this.intRow.addRowUI && (this.value === undefined || this.value === null);
1,212,645✔
111
    }
112

113
    /**
114
     * @hidden
115
     * @internal
116
     */
117
    @ViewChildren('error', { read: IgxTooltipDirective })
118
    public errorTooltip: QueryList<IgxTooltipDirective>;
119

120
    /**
121
     * @hidden
122
     * @internal
123
     */
124
    @ViewChild('errorIcon', { read: IgxIconComponent, static: false })
125
    public errorIcon: IgxIconComponent;
126

127
    /**
128
     * Gets the default error template.
129
     * @hidden @internal
130
     */
131
    @ViewChild('defaultError', { read: TemplateRef, static: true })
132
    public defaultErrorTemplate: TemplateRef<any>;
133

134
    /**
135
     * Gets the column of the cell.
136
     * ```typescript
137
     *  let cellColumn = this.cell.column;
138
     * ```
139
     *
140
     * @memberof IgxGridCellComponent
141
     */
142
    @Input()
143
    public column: ColumnType;
144

145

146
    /**
147
     * @hidden
148
     * @internal
149
     */
150
    protected get formGroup(): FormGroup {
151
        return this.grid.validation.getFormGroup(this.intRow.key);
5,823,089✔
152
    }
153

154
    /**
155
     * @hidden
156
     * @internal
157
     */
158
    @Input()
159
    public intRow: IgxRowDirective;
160

161
    /**
162
     * Gets the row of the cell.
163
     * ```typescript
164
     * let cellRow = this.cell.row;
165
     * ```
166
     *
167
     * @memberof IgxGridCellComponent
168
     */
169
    @Input()
170
    public get row(): RowType {
171
        return this.grid.createRow(this.intRow.index);
1,794✔
172
    }
173

174
    /**
175
     * Gets the data of the row of the cell.
176
     * ```typescript
177
     * let rowData = this.cell.rowData;
178
     * ```
179
     *
180
     * @memberof IgxGridCellComponent
181
     */
182
    @Input()
183
    public rowData: any;
184

185
    /**
186
     * @hidden
187
     * @internal
188
     */
189
    @Input()
190
    public columnData: any;
191

192
    /**
193
     * Sets/gets the template of the cell.
194
     * ```html
195
     * <ng-template #cellTemplate igxCell let-value>
196
     *   <div style="font-style: oblique; color:blueviolet; background:red">
197
     *       <span>{{value}}</span>
198
     *   </div>
199
     * </ng-template>
200
     * ```
201
     * ```typescript
202
     * @ViewChild('cellTemplate',{read: TemplateRef})
203
     * cellTemplate: TemplateRef<any>;
204
     * ```
205
     * ```typescript
206
     * this.cell.cellTemplate = this.cellTemplate;
207
     * ```
208
     * ```typescript
209
     * let template =  this.cell.cellTemplate;
210
     * ```
211
     *
212
     * @memberof IgxGridCellComponent
213
     */
214
    @Input()
215
    public cellTemplate: TemplateRef<any>;
216

217
    @Input()
218
    public cellValidationErrorTemplate: TemplateRef<any>;
219

220
    @Input()
221
    public pinnedIndicator: TemplateRef<any>;
222

223
    /**
224
     * Sets/gets the cell value.
225
     * ```typescript
226
     * this.cell.value = "Cell Value";
227
     * ```
228
     * ```typescript
229
     * let cellValue = this.cell.value;
230
     * ```
231
     *
232
     * @memberof IgxGridCellComponent
233
     */
234
    @Input()
235
    public value: any;
236

237
    /**
238
     * Gets the cell formatter.
239
     * ```typescript
240
     * let cellForamatter = this.cell.formatter;
241
     * ```
242
     *
243
     * @memberof IgxGridCellComponent
244
     */
245
    @Input()
246
    public formatter: (value: any, rowData?: any, columnData?: any) => any;
247

248
    /**
249
     * Gets the cell template context object.
250
     * ```typescript
251
     *  let context = this.cell.context();
252
     * ```
253
     *
254
     * @memberof IgxGridCellComponent
255
     */
256
    public get context(): IgxCellTemplateContext {
257
        const getCellType = () => this.getCellType(true);
647,648✔
258
        const ctx: IgxCellTemplateContext = {
647,648✔
259
            $implicit: this.value,
260
            additionalTemplateContext: this.column.additionalTemplateContext,
261
            get cell() {
262
                /* Turns the `cell` property from the template context object into lazy-evaluated one.
263
                 * Otherwise on each detection cycle the cell template is recreating N cell instances where
264
                 * N = number of visible cells in the grid, leading to massive performance degradation in large grids.
265
                 */
266
                return getCellType();
1,998✔
267
            }
268
        };
269
        if (this.editMode) {
647,648✔
270
            ctx.formControl = this.formControl;
2,457✔
271
        }
272
        if (this.isInvalid) {
647,648✔
273
            ctx.defaultErrorTemplate = this.defaultErrorTemplate;
414✔
274
        }
275
        return ctx;
647,648✔
276
    }
277

278
    /**
279
     * Gets the cell template.
280
     * ```typescript
281
     * let template = this.cell.template;
282
     * ```
283
     *
284
     * @memberof IgxGridCellComponent
285
     */
286
    public get template(): TemplateRef<any> {
287
        if (this.editMode && this.formGroup) {
323,779✔
288
            const inlineEditorTemplate = this.column.inlineEditorTemplate;
1,227✔
289
            return inlineEditorTemplate ? inlineEditorTemplate : this.inlineEditorTemplate;
1,227✔
290
        }
291
        if (this.cellTemplate) {
322,552✔
292
            return this.cellTemplate;
691✔
293
        }
294
        if (this.grid.rowEditable && this.intRow.addRowUI) {
321,861✔
295
            return this.addRowCellTemplate;
1,918✔
296
        }
297
        return this.defaultCellTemplate;
319,943✔
298
    }
299

300
    /**
301
     * Gets the pinned indicator template.
302
     * ```typescript
303
     * let template = this.cell.pinnedIndicatorTemplate;
304
     * ```
305
     *
306
     * @memberof IgxGridCellComponent
307
     */
308
    public get pinnedIndicatorTemplate() {
309
        if (this.pinnedIndicator) {
323,731!
310
            return this.pinnedIndicator;
×
311
        }
312
        return this.defaultPinnedIndicator;
323,731✔
313
    }
314

315
    /**
316
     * Gets the `id` of the grid in which the cell is stored.
317
     * ```typescript
318
     * let gridId = this.cell.gridID;
319
     * ```
320
     *
321
     * @memberof IgxGridCellComponent
322
     */
323
    public get gridID(): any {
324
        return this.intRow.gridID;
302,809✔
325
    }
326

327

328
    /**
329
     * Gets the `index` of the row where the cell is stored.
330
     * ```typescript
331
     * let rowIndex = this.cell.rowIndex;
332
     * ```
333
     *
334
     * @memberof IgxGridCellComponent
335
     */
336
    @HostBinding('attr.data-rowIndex')
337
    public get rowIndex(): number {
338
        return this.intRow.index;
4,848,495✔
339
    }
340

341
    /**
342
     * Gets the `index` of the cell column.
343
     * ```typescript
344
     * let columnIndex = this.cell.columnIndex;
345
     * ```
346
     *
347
     * @memberof IgxGridCellComponent
348
     */
349
    public get columnIndex(): number {
350
        return this.column.index;
17,840✔
351
    }
352

353
    /**
354
     * Returns the column visible index.
355
     * ```typescript
356
     * let visibleColumnIndex = this.cell.visibleColumnIndex;
357
     * ```
358
     *
359
     * @memberof IgxGridCellComponent
360
     */
361
    @HostBinding('attr.data-visibleIndex')
362
    @Input()
363
    public get visibleColumnIndex() {
364
        return this.column.columnLayoutChild ? this.column.visibleIndex : this._vIndex;
4,851,166✔
365
    }
366

367
    public set visibleColumnIndex(val) {
368
        this._vIndex = val;
158,642✔
369
    }
370

371
    /**
372
     * Gets the ID of the cell.
373
     * ```typescript
374
     * let cellID = this.cell.cellID;
375
     * ```
376
     *
377
     * @memberof IgxGridCellComponent
378
     */
379
    public get cellID() {
380
        const primaryKey = this.grid.primaryKey;
459✔
381
        const rowID = primaryKey ? this.rowData[primaryKey] : this.rowData;
459✔
382
        return { rowID, columnID: this.columnIndex, rowIndex: this.rowIndex };
459✔
383
    }
384

385
    @HostBinding('attr.id')
386
    public get attrCellID() {
387
        return `${this.intRow.gridID}_${this.rowIndex}_${this.visibleColumnIndex}`;
1,210,774✔
388
    }
389

390
    @HostBinding('attr.title')
391
    public get title() {
392
        if (this.editMode || this.cellTemplate || this.errorShowing) {
1,210,787✔
393
            return '';
5,231✔
394
        }
395

396
        if (this.formatter) {
1,205,556✔
397
            return this.formatter(this.value, this.rowData, this.columnData);
21,895✔
398
        }
399

400
        const args = this.column.pipeArgs;
1,183,661✔
401
        const locale = this.grid.locale;
1,183,661✔
402

403
        switch (this.column.dataType) {
1,183,661✔
404
            case GridColumnDataType.Percent:
405
                return formatPercent(this.value, locale, args.digitsInfo);
427✔
406
            case GridColumnDataType.Currency:
407
                return formatCurrency(this.value, this.currencyCode, args.display, args.digitsInfo, locale);
20,409✔
408
            case GridColumnDataType.Date:
409
            case GridColumnDataType.DateTime:
410
            case GridColumnDataType.Time:
411
                return formatDate(this.value, args.format, locale, args.timezone);
169,986✔
412
        }
413
        return this.value;
992,839✔
414
    }
415

416
    @HostBinding('class.igx-grid__td--bool-true')
417
    public get booleanClass() {
418
        return this.column.dataType === 'boolean' && this.value;
1,210,774✔
419
    }
420

421
    /**
422
     * Returns a reference to the nativeElement of the cell.
423
     * ```typescript
424
     * let cellNativeElement = this.cell.nativeElement;
425
     * ```
426
     *
427
     * @memberof IgxGridCellComponent
428
     */
429
    public get nativeElement(): HTMLElement {
430
        return this.element.nativeElement;
1,273,252✔
431
    }
432

433
    /**
434
     * @hidden
435
     * @internal
436
     */
437
    @Input()
438
    public get cellSelectionMode() {
439
        return this._cellSelection;
305,413✔
440
    }
441

442
    public set cellSelectionMode(value) {
443
        if (this._cellSelection === value) {
152,566✔
444
            return;
151,594✔
445
        }
446
        this.zone.runOutsideAngular(() => {
972✔
447
            if (value === GridSelectionMode.multiple) {
972✔
448
                this.addPointerListeners(value);
60✔
449
            } else {
450
                this.removePointerListeners(this._cellSelection);
912✔
451
            }
452
        });
453
        this._cellSelection = value;
972✔
454
    }
455

456
    /**
457
     * @hidden
458
     * @internal
459
     */
460
    @Input()
461
    public set lastSearchInfo(value: ISearchInfo) {
462
        this._lastSearchInfo = value;
157,498✔
463
        this.highlightText(this._lastSearchInfo.searchText, this._lastSearchInfo.caseSensitive, this._lastSearchInfo.exactMatch);
157,498✔
464
    }
465

466
    /**
467
     * @hidden
468
     * @internal
469
     */
470
    @Input()
471
    @HostBinding('class.igx-grid__td--pinned-last')
472
    public lastPinned = false;
152,198✔
473

474
    /**
475
     * @hidden
476
     * @internal
477
     */
478
    @Input()
479
    @HostBinding('class.igx-grid__td--pinned-first')
480
    public firstPinned = false;
152,198✔
481

482
    /**
483
     * Returns whether the cell is in edit mode.
484
     */
485
    @Input({ transform: booleanAttribute })
486
    @HostBinding('class.igx-grid__td--editing')
487
    public editMode = false;
152,198✔
488

489
    /**
490
     * Sets/get the `role` property of the cell.
491
     * Default value is `"gridcell"`.
492
     * ```typescript
493
     * this.cell.role = 'grid-cell';
494
     * ```
495
     * ```typescript
496
     * let cellRole = this.cell.role;
497
     * ```
498
     *
499
     * @memberof IgxGridCellComponent
500
     */
501
    @HostBinding('attr.role')
502
    public role = 'gridcell';
152,198✔
503

504
    /**
505
     * Gets whether the cell is editable.
506
     * ```typescript
507
     * let isCellReadonly = this.cell.readonly;
508
     * ```
509
     *
510
     * @memberof IgxGridCellComponent
511
     */
512
    @HostBinding('attr.aria-readonly')
513
    public get readonly(): boolean {
514
        return !this.editable;
1,210,775✔
515
    }
516

517
    /** @hidden @internal */
518
    @HostBinding('attr.aria-describedby')
519
    public get ariaDescribeBy() {
520
        let describeBy = this.grid.headerGroupsList
1,211,855✔
521
                        .find(hg => hg.column.field === this.column.field)?.headerID || '';
4,384,948✔
522
        if (this.isInvalid) {
1,211,855✔
523
            describeBy += ' ' + this.ariaErrorMessage;
107✔
524
        }
525
        return describeBy;
1,211,855✔
526
    }
527

528
    /** @hidden @internal */
529
    public get ariaErrorMessage() {
530
        return this.grid.id + '_' + this.column.field + '_' + this.intRow.index + '_error';
245✔
531
    }
532

533
    /**
534
     * @hidden
535
     * @internal
536
     */
537
    @HostBinding('class.igx-grid__td--invalid')
538
    @HostBinding('attr.aria-invalid')
539
    public get isInvalid() {
540
        const isInvalid = this.formGroup?.get(this.column?.field)?.invalid && this.formGroup?.get(this.column?.field)?.touched;
4,606,927✔
541
        return !this.intRow.deleted && isInvalid;
4,606,927✔
542
    }
543

544
    /**
545
     * @hidden
546
     * @internal
547
     */
548
    @HostBinding('class.igx-grid__td--valid')
549
    public get isValidAfterEdit() {
550
        const formControl = this.formGroup?.get(this.column?.field);
1,210,774✔
551
        return this.editMode && formControl && !formControl.invalid && formControl.dirty;
1,210,774✔
552
    }
553

554
    /**
555
     * Gets the formControl responsible for value changes and validation for this cell.
556
     */
557
    protected get formControl(): FormControl {
558
        return this.grid.validation.getFormControl(this.intRow.key, this.column.field) as FormControl;
5,040✔
559
    }
560

561
    public get gridRowSpan(): number {
562
        return this.column.gridRowSpan;
198✔
563
    }
564

565
    public get gridColumnSpan(): number {
566
        return this.column.gridColumnSpan;
198✔
567
    }
568

569
    public get rowEnd(): number {
570
        return this.column.rowEnd;
×
571
    }
572

573
    public get colEnd(): number {
574
        return this.column.colEnd;
×
575
    }
576

577
    public get rowStart(): number {
578
        return this.column.rowStart;
×
579
    }
580

581
    public get colStart(): number {
582
        return this.column.colStart;
×
583
    }
584

585
    /**
586
     * Gets the width of the cell.
587
     * ```typescript
588
     * let cellWidth = this.cell.width;
589
     * ```
590
     *
591
     * @memberof IgxGridCellComponent
592
     */
593
    @Input()
594
    public width = '';
152,198✔
595

596
    /**
597
     * @hidden
598
     */
599
    @Input()
600
    @HostBinding('class.igx-grid__td--active')
601
    public active = false;
152,198✔
602

603
    @HostBinding('attr.aria-selected')
604
    public get ariaSelected() {
605
        return this.selected || this.column.selected || this.intRow.selected;
1,210,774✔
606
    }
607

608
    /**
609
     * Gets whether the cell is selected.
610
     * ```typescript
611
     * let isSelected = this.cell.selected;
612
     * ```
613
     *
614
     * @memberof IgxGridCellComponent
615
     */
616
    @HostBinding('class.igx-grid__td--selected')
617
    public get selected() {
618
        return this.selectionService.selected(this.selectionNode);
2,423,633✔
619
    }
620

621
    /**
622
     * Selects/deselects the cell.
623
     * ```typescript
624
     * this.cell.selected = true.
625
     * ```
626
     *
627
     * @memberof IgxGridCellComponent
628
     */
629
    public set selected(val: boolean) {
630
        const node = this.selectionNode;
1✔
631
        if (val) {
1!
632
            this.selectionService.add(node);
1✔
633
        } else {
634
            this.selectionService.remove(node);
×
635
        }
636
        this.grid.notifyChanges();
1✔
637
    }
638

639
    /**
640
     * Gets whether the cell column is selected.
641
     * ```typescript
642
     * let isCellColumnSelected = this.cell.columnSelected;
643
     * ```
644
     *
645
     * @memberof IgxGridCellComponent
646
     */
647
    @HostBinding('class.igx-grid__td--column-selected')
648
    public get columnSelected() {
649
        return this.selectionService.isColumnSelected(this.column.field);
1,210,774✔
650
    }
651

652
    /**
653
     * Sets the current edit value while a cell is in edit mode.
654
     * Only for cell editing mode.
655
     * ```typescript
656
     * this.cell.editValue = value;
657
     * ```
658
     *
659
     * @memberof IgxGridCellComponent
660
     */
661
    public set editValue(value) {
662
        if (this.grid.crudService.cellInEditMode) {
44✔
663
            this.grid.crudService.cell.editValue = value;
44✔
664
        }
665
    }
666

667
    /**
668
     * Gets the current edit value while a cell is in edit mode.
669
     * Only for cell editing mode.
670
     * ```typescript
671
     * let editValue = this.cell.editValue;
672
     * ```
673
     *
674
     * @memberof IgxGridCellComponent
675
     */
676
    public get editValue() {
677
        if (this.grid.crudService.cellInEditMode) {
163✔
678
            return this.grid.crudService.cell.editValue;
163✔
679
        }
680
    }
681

682
    /**
683
     * Returns whether the cell is editable.
684
     */
685
    public get editable(): boolean {
686
        return this.column.editable && !this.intRow.disabled;
1,212,040✔
687
    }
688

689
    /**
690
     * @hidden
691
     */
692
    @Input()
693
    @HostBinding('class.igx-grid__td--row-pinned-first')
694
    public displayPinnedChip = false;
152,198✔
695

696
    @HostBinding('style.min-height.px')
697
    protected get minHeight() {
698
        if ((this.grid as any).isCustomSetRowHeight) {
1,210,774✔
699
            return this.grid.renderedRowHeight;
464✔
700
        }
701
    }
702

703
    @ViewChild('defaultCell', { read: TemplateRef, static: true })
704
    protected defaultCellTemplate: TemplateRef<any>;
705

706
    @ViewChild('defaultPinnedIndicator', { read: TemplateRef, static: true })
707
    protected defaultPinnedIndicator: TemplateRef<any>;
708

709
    @ViewChild('inlineEditor', { read: TemplateRef, static: true })
710
    protected inlineEditorTemplate: TemplateRef<any>;
711

712
    @ViewChild('addRowCell', { read: TemplateRef, static: true })
713
    protected addRowCellTemplate: TemplateRef<any>;
714

715
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
716
    protected set highlight(value: IgxTextHighlightDirective) {
717
        this._highlight = value;
154,222✔
718

719
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
154,222✔
720
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
399✔
721
                this.grid.lastSearchInfo.caseSensitive,
722
                this.grid.lastSearchInfo.exactMatch);
723
            this._highlight.activateIfNecessary();
399✔
724
        }
725
    }
726

727
    protected get highlight() {
728
        return this._highlight;
352,530✔
729
    }
730

731
    protected get selectionNode(): ISelectionNode {
732
        return {
2,425,510✔
733
            row: this.rowIndex,
734
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.visibleColumnIndex,
2,425,510✔
735
            layout: this.column.columnLayoutChild ? {
2,425,510✔
736
                rowStart: this.column.rowStart,
737
                colStart: this.column.colStart,
738
                rowEnd: this.column.rowEnd,
739
                colEnd: this.column.colEnd,
740
                columnVisibleIndex: this.visibleColumnIndex
741
            } : null
742
        };
743
    }
744

745
    /**
746
     * Sets/gets the highlight class of the cell.
747
     * Default value is `"igx-highlight"`.
748
     * ```typescript
749
     * let highlightClass = this.cell.highlightClass;
750
     * ```
751
     * ```typescript
752
     * this.cell.highlightClass = 'igx-cell-highlight';
753
     * ```
754
     *
755
     * @memberof IgxGridCellComponent
756
     */
757
    public highlightClass = 'igx-highlight';
152,198✔
758

759
    /**
760
     * Sets/gets the active highlight class class of the cell.
761
     * Default value is `"igx-highlight__active"`.
762
     * ```typescript
763
     * let activeHighlightClass = this.cell.activeHighlightClass;
764
     * ```
765
     * ```typescript
766
     * this.cell.activeHighlightClass = 'igx-cell-highlight_active';
767
     * ```
768
     *
769
     * @memberof IgxGridCellComponent
770
     */
771
    public activeHighlightClass = 'igx-highlight__active';
152,198✔
772

773
    /** @hidden @internal */
774
    public get step(): number {
775
        const digitsInfo = this.column.pipeArgs.digitsInfo;
218✔
776
        if (!digitsInfo) {
218!
UNCOV
777
            return 1;
×
778
        }
779
        const step = +digitsInfo.substr(digitsInfo.indexOf('.') + 1, 1);
218✔
780
        return 1 / (Math.pow(10, step));
218✔
781
    }
782

783
    /** @hidden @internal */
784
    public get currencyCode(): string {
785
        return this.column.pipeArgs.currencyCode ?
57,459✔
786
            this.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
787
    }
788

789
    /** @hidden @internal */
790
    public get currencyCodeSymbol(): string {
791
        return getCurrencySymbol(this.currencyCode, 'wide', this.grid.locale);
4✔
792
    }
793

794
    protected _lastSearchInfo: ISearchInfo;
795
    private _highlight: IgxTextHighlightDirective;
796
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
152,198✔
797
    private _vIndex = -1;
152,198✔
798

799
    constructor(
800
        protected selectionService: IgxGridSelectionService,
152,198✔
801
        @Inject(IGX_GRID_BASE) public grid: GridType,
152,198✔
802
        @Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
152,198✔
803
        public cdr: ChangeDetectorRef,
152,198✔
804
        private element: ElementRef<HTMLElement>,
152,198✔
805
        protected zone: NgZone,
152,198✔
806
        private touchManager: HammerGesturesManager,
152,198✔
807
        protected platformUtil: PlatformUtil
152,198✔
808
    ) { }
809

810
    /**
811
     * @hidden
812
     * @internal
813
     */
814
    @HostListener('dblclick', ['$event'])
815
    public onDoubleClick = (event: MouseEvent) => {
152,198✔
816
        if (event.type === 'doubletap') {
150✔
817
            // prevent double-tap to zoom on iOS
818
            event.preventDefault();
1✔
819
        }
820
        if (this.editable && !this.editMode && !this.intRow.deleted && !this.grid.crudService.rowEditingBlocked) {
150✔
821
            this.grid.crudService.enterEditMode(this, event as Event);
144✔
822
        }
823

824
        this.grid.doubleClick.emit({
150✔
825
            cell: this.getCellType(),
826
            event
827
        });
828
    };
829

830
    /**
831
     * @hidden
832
     * @internal
833
     */
834
    @HostListener('click', ['$event'])
835
    public onClick(event: MouseEvent) {
836
        this.grid.cellClick.emit({
260✔
837
            cell: this.getCellType(),
838
            event
839
        });
840
    }
841

842
    /**
843
     * @hidden
844
     * @internal
845
     */
846
    public ngOnInit() {
847
        this.zone.runOutsideAngular(() => {
152,198✔
848
            this.nativeElement.addEventListener('pointerdown', this.pointerdown);
152,198✔
849
            this.addPointerListeners(this.cellSelectionMode);
152,198✔
850
        });
851
        if (this.platformUtil.isIOS) {
152,198✔
852
            this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
40✔
853
                cssProps: {} /* don't disable user-select, etc */
854
            });
855
        }
856

857
    }
858

859
    public ngAfterViewInit() {
860
        this.errorTooltip.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
152,198✔
861
            if (this.errorTooltip.length > 0 && this.active) {
43✔
862
                // error ocurred
863
                this.cdr.detectChanges();
24✔
864
                this.openErrorTooltip();
24✔
865
            }
866
        });
867
    }
868

869
    /**
870
     * @hidden
871
     * @internal
872
     */
873
    public errorShowing = false;
152,198✔
874

875
    private openErrorTooltip() {
876
        const tooltip = this.errorTooltip.first;
25✔
877
        tooltip.open(
25✔
878
            {
879
                target: this.errorIcon.el.nativeElement,
880
                closeOnOutsideClick: true,
881
                excludeFromOutsideClick: [this.nativeElement],
882
                closeOnEscape: false,
883
                outlet: this.grid.outlet,
884
                modal: false,
885
                positionStrategy: new AutoPositionStrategy({
886
                    horizontalStartPoint: HorizontalAlignment.Center,
887
                    horizontalDirection: HorizontalAlignment.Center
888
                })
889
            }
890
        );
891
    }
892

893
    /**
894
     * @hidden
895
     * @internal
896
     */
897
    public ngOnDestroy() {
898
        this.zone.runOutsideAngular(() => {
150,853✔
899
            this.nativeElement.removeEventListener('pointerdown', this.pointerdown);
150,853✔
900
            this.removePointerListeners(this.cellSelectionMode);
150,853✔
901
        });
902
        this.touchManager.destroy();
150,853✔
903
        this._destroy$.next();
150,853✔
904
        this._destroy$.complete();
150,853✔
905
    }
906

907
    /**
908
     * @hidden
909
     * @internal
910
     */
911
    public ngOnChanges(changes: SimpleChanges): void {
912
        if (changes.editMode && changes.editMode.currentValue && this.formControl) {
290,385✔
913
            // ensure when values change, form control is forced to be marked as touche.
914
            this.formControl.valueChanges.pipe(takeWhile(() => this.editMode)).subscribe(() => this.formControl.markAsTouched());
397✔
915
            // while in edit mode subscribe to value changes on the current form control and set to editValue
916
            this.formControl.statusChanges.pipe(takeWhile(() => this.editMode)).subscribe(status => {
397✔
917
                if (status === 'INVALID' && this.errorTooltip.length > 0) {
189!
UNCOV
918
                    this.cdr.detectChanges();
×
UNCOV
919
                    const tooltip = this.errorTooltip.first;
×
UNCOV
920
                    this.resizeAndRepositionOverlayById(tooltip.overlayId, this.errorTooltip.first.element.offsetWidth);
×
921
                }
922
            });
923
        }
924
        if (changes.value && !changes.value.firstChange) {
290,385✔
925
            if (this.highlight) {
47,675✔
926
                this.highlight.lastSearchInfo.searchText = this.grid.lastSearchInfo.searchText;
45,285✔
927
                this.highlight.lastSearchInfo.caseSensitive = this.grid.lastSearchInfo.caseSensitive;
45,285✔
928
                this.highlight.lastSearchInfo.exactMatch = this.grid.lastSearchInfo.exactMatch;
45,285✔
929
            }
930
        }
931
    }
932

933

934

935
    /**
936
     * @hidden @internal
937
     */
938
    private resizeAndRepositionOverlayById(overlayId: string, newSize: number) {
UNCOV
939
        const overlay = this.overlayService.getOverlayById(overlayId);
×
UNCOV
940
        if (!overlay) return;
×
UNCOV
941
        overlay.initialSize.width = newSize;
×
UNCOV
942
        overlay.elementRef.nativeElement.parentElement.style.width = newSize + 'px';
×
UNCOV
943
        this.overlayService.reposition(overlayId);
×
944
    }
945

946
    /**
947
     * Starts/ends edit mode for the cell.
948
     *
949
     * ```typescript
950
     * cell.setEditMode(true);
951
     * ```
952
     */
953
    public setEditMode(value: boolean): void {
954
        if (this.intRow.deleted) {
30!
UNCOV
955
            return;
×
956
        }
957
        if (this.editable && value) {
30✔
958
            if (this.grid.crudService.cellInEditMode) {
26✔
959
                this.grid.gridAPI.update_cell(this.grid.crudService.cell);
5✔
960
                this.grid.crudService.endCellEdit();
5✔
961
            }
962
            this.grid.crudService.enterEditMode(this);
26✔
963
        } else {
964
            this.grid.crudService.endCellEdit();
4✔
965
        }
966
        this.grid.notifyChanges();
30✔
967
    }
968

969
    /**
970
     * Sets new value to the cell.
971
     * ```typescript
972
     * this.cell.update('New Value');
973
     * ```
974
     *
975
     * @memberof IgxGridCellComponent
976
     */
977
    // TODO: Refactor
978
    public update(val: any) {
979
        if (this.intRow.deleted) {
33!
UNCOV
980
            return;
×
981
        }
982

983
        let cell = this.grid.crudService.cell;
33✔
984
        if (!cell) {
33✔
985
            cell = this.grid.crudService.createCell(this);
14✔
986
        }
987
        cell.editValue = val;
33✔
988
        this.grid.gridAPI.update_cell(cell);
33✔
989
        this.grid.crudService.endCellEdit();
33✔
990
        this.cdr.markForCheck();
33✔
991
    }
992

993
    /**
994
     *
995
     * @hidden
996
     * @internal
997
     */
998
    public pointerdown = (event: PointerEvent) => {
152,198✔
999
        if (this.cellSelectionMode !== GridSelectionMode.multiple) {
424✔
1000
            this.activate(event);
23✔
1001
            return;
23✔
1002
        }
1003
        if (!this.platformUtil.isLeftClick(event)) {
401✔
1004
            event.preventDefault();
4✔
1005
            this.grid.navigation.setActiveNode({ rowIndex: this.rowIndex, colIndex: this.visibleColumnIndex });
4✔
1006
            this.selectionService.addKeyboardRange();
4✔
1007
            this.selectionService.initKeyboardState();
4✔
1008
            this.selectionService.primaryButton = false;
4✔
1009
            // Ensure RMB Click on edited cell does not end cell editing
1010
            if (!this.selected) {
4✔
1011
                this.grid.crudService.updateCell(true, event);
2✔
1012
            }
1013
            return;
4✔
1014
        } else {
1015
            this.selectionService.primaryButton = true;
397✔
1016
        }
1017
        this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);
397✔
1018
        this.activate(event);
397✔
1019
    };
1020

1021
    /**
1022
     *
1023
     * @hidden
1024
     * @internal
1025
     */
1026
    public pointerenter = (event: PointerEvent) => {
152,198✔
1027
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
118✔
1028
        if (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
118✔
1029
            return;
3✔
1030
        }
1031
        const dragMode = this.selectionService.pointerEnter(this.selectionNode, event);
115✔
1032
        if (dragMode) {
115✔
1033
            this.grid.cdr.detectChanges();
114✔
1034
        }
1035
    };
1036

1037
    /**
1038
     * @hidden
1039
     * @internal
1040
     */
1041
    public focusout = () => {
152,198✔
1042
        this.closeErrorTooltip();
48✔
1043
    }
1044

1045
    private closeErrorTooltip() {
1046
        const tooltip = this.errorTooltip.first;
48✔
1047
        if (tooltip) {
48!
UNCOV
1048
            tooltip.close();
×
1049
        }
1050
    }
1051

1052
    /**
1053
     * @hidden
1054
     * @internal
1055
     */
1056
    public pointerup = (event: PointerEvent) => {
152,198✔
1057
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
398✔
1058
        if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
398✔
1059
            this.grid.navigation.activeNode.gridID !== this.gridID))) {
1060
            return;
4✔
1061
        }
1062
        if (this.selectionService.pointerUp(this.selectionNode, this.grid.rangeSelected)) {
394✔
1063
            this.grid.cdr.detectChanges();
49✔
1064
        }
1065
    };
1066

1067
    /**
1068
     * @hidden
1069
     * @internal
1070
     */
1071
    public activate(event: FocusEvent | KeyboardEvent) {
1072
        const node = this.selectionNode;
970✔
1073
        let shouldEmitSelection = !this.selectionService.isActiveNode(node);
970✔
1074

1075
        if (this.selectionService.primaryButton) {
970!
1076
            const currentActive = this.selectionService.activeElement;
970✔
1077
            if (this.cellSelectionMode === GridSelectionMode.single && (event as any)?.ctrlKey && this.selected) {
970✔
1078
                this.selectionService.activeElement = null;
1✔
1079
                shouldEmitSelection = true;
1✔
1080
            } else {
1081
                this.selectionService.activeElement = node;
969✔
1082
            }
1083
            const cancel = this._updateCRUDStatus(event);
970✔
1084
            if (cancel) {
970✔
1085
                this.selectionService.activeElement = currentActive;
2✔
1086
                return;
2✔
1087
            }
1088

1089
            const activeElement = this.selectionService.activeElement;
968✔
1090
            const row = activeElement ? this.grid.gridAPI.get_row_by_index(activeElement.row) : null;
968✔
1091
            if (this.grid.crudService.rowEditingBlocked && row && this.intRow.key !== row.key) {
968!
UNCOV
1092
                return;
×
1093
            }
1094

1095
        } else {
UNCOV
1096
            this.selectionService.activeElement = null;
×
UNCOV
1097
            if (this.grid.crudService.cellInEditMode && !this.editMode) {
×
UNCOV
1098
                this.grid.crudService.updateCell(true, event);
×
1099
            }
1100
        }
1101

1102
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
968✔
1103

1104
        const isTargetErrorIcon = event && event.target && event.target === this.errorIcon?.el.nativeElement
968✔
1105
        if (this.isInvalid && !isTargetErrorIcon) {
968✔
1106
            this.cdr.detectChanges();
1✔
1107
            this.openErrorTooltip();
1✔
1108
            this.grid.activeNodeChange.pipe(first()).subscribe(() => {
1✔
UNCOV
1109
                this.closeErrorTooltip();
×
1110
            });
1111
        }
1112
        this.selectionService.primaryButton = true;
968✔
1113
        if (this.cellSelectionMode === GridSelectionMode.multiple && this.selectionService.activeElement) {
968✔
1114
            if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any)?.ctrlKey && !(event as any)?.shiftKey) {
936✔
1115
                this.selectionService.remove(this.selectionService.activeElement);
3✔
1116
                shouldEmitSelection = true;
3✔
1117
            } else {
1118
                this.selectionService.add(this.selectionService.activeElement, false); // pointer events handle range generation
933✔
1119
                this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
933✔
1120
            }
1121
        }
1122
        if (this.grid.isCellSelectable && shouldEmitSelection) {
968✔
1123
            this.zone.run(() => this.grid.selected.emit({ cell: this.getCellType(), event }));
941✔
1124
        }
1125
    }
1126

1127
    /**
1128
     * If the provided string matches the text in the cell, the text gets highlighted.
1129
     * ```typescript
1130
     * this.cell.highlightText('Cell Value', true);
1131
     * ```
1132
     *
1133
     * @memberof IgxGridCellComponent
1134
     */
1135
    public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean): number {
1136
        return this.highlight && this.column.searchable ? this.highlight.highlight(text, caseSensitive, exactMatch) : 0;
160,595✔
1137
    }
1138

1139
    /**
1140
     * Clears the highlight of the text in the cell.
1141
     * ```typescript
1142
     * this.cell.clearHighLight();
1143
     * ```
1144
     *
1145
     * @memberof IgxGridCellComponent
1146
     */
1147
    public clearHighlight() {
1148
        if (this.highlight && this.column.searchable) {
40✔
1149
            this.highlight.clearHighlight();
40✔
1150
        }
1151
    }
1152

1153
    /**
1154
     * @hidden
1155
     * @internal
1156
     */
1157
    public calculateSizeToFit(range: any): number {
1158
        return this.platformUtil.getNodeSizeViaRange(range, this.nativeElement);
214✔
1159
    }
1160

1161
    /**
1162
     * @hidden
1163
     * @internal
1164
     */
1165
    public get searchMetadata() {
1166
        const meta = new Map<string, any>();
302,668✔
1167
        meta.set('pinned', this.grid.isRecordPinnedByViewIndex(this.intRow.index));
302,668✔
1168
        return meta;
302,668✔
1169
    }
1170

1171
    /**
1172
     * @hidden
1173
     * @internal
1174
     */
1175
    private _updateCRUDStatus(event?: Event) {
1176
        if (this.editMode) {
970✔
1177
            return;
48✔
1178
        }
1179

1180
        let editableArgs;
1181
        const crud = this.grid.crudService;
922✔
1182
        const editableCell = this.grid.crudService.cell;
922✔
1183
        const editMode = !!(crud.row || crud.cell);
922✔
1184

1185
        if (this.editable && editMode && !this.intRow.deleted) {
922✔
1186
            if (editableCell) {
88✔
1187
                editableArgs = this.grid.crudService.updateCell(false, event);
77✔
1188

1189
                /* This check is related with the following issue #6517:
1190
                 * when edit cell that belongs to a column which is sorted and press tab,
1191
                 * the next cell in edit mode is with wrong value /its context is not updated/;
1192
                 * So we reapply sorting before the next cell enters edit mode.
1193
                 * Also we need to keep the notifyChanges below, because of the current
1194
                 * change detection cycle when we have editing with enabled transactions
1195
                 */
1196
                if (this.grid.sortingExpressions.length && this.grid.sortingExpressions.indexOf(editableCell.column.field)) {
77!
UNCOV
1197
                    this.grid.cdr.detectChanges();
×
1198
                }
1199

1200
                if (editableArgs && editableArgs.cancel) {
77✔
1201
                    return true;
2✔
1202
                }
1203

1204
                crud.exitCellEdit(event);
75✔
1205
            }
1206
            this.grid.tbody.nativeElement.focus({ preventScroll: true });
86✔
1207
            this.grid.notifyChanges();
86✔
1208
            crud.enterEditMode(this, event);
86✔
1209
            return false;
86✔
1210
        }
1211

1212
        if (editableCell && crud.sameRow(this.cellID.rowID)) {
834✔
1213
            this.grid.crudService.updateCell(true, event);
1✔
1214
        } else if (editMode && !crud.sameRow(this.cellID.rowID)) {
833✔
1215
            this.grid.crudService.endEdit(true, event);
3✔
1216
        }
1217
    }
1218

1219
    private addPointerListeners(selection) {
1220
        if (selection !== GridSelectionMode.multiple) {
152,258✔
1221
            return;
604✔
1222
        }
1223
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
151,654✔
1224
        this.nativeElement.addEventListener('pointerup', this.pointerup);
151,654✔
1225
        this.nativeElement.addEventListener('focusout', this.focusout);
151,654✔
1226
    }
1227

1228
    private removePointerListeners(selection) {
1229
        if (selection !== GridSelectionMode.multiple) {
151,765✔
1230
            return;
852✔
1231
        }
1232
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
150,913✔
1233
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
150,913✔
1234
        this.nativeElement.removeEventListener('focusout', this.focusout);
150,913✔
1235
    }
1236

1237
    private getCellType(useRow?: boolean): CellType {
1238
        const rowID = useRow ? this.grid.createRow(this.intRow.index, this.intRow.data) : this.intRow.index;
3,349✔
1239
        return new IgxGridCell(this.grid, rowID, this.column);
3,349✔
1240
    }
1241
}
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