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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

1.85
/projects/igniteui-angular/src/lib/tabs/tabs/tab-header.component.ts
1
import { AfterViewInit, Component, ElementRef, HostBinding, HostListener, NgZone, OnDestroy } from '@angular/core';
2
import { IgxTabItemDirective } from '../tab-item.directive';
3
import { IgxTabHeaderDirective } from '../tab-header.directive';
4
import { IgxTabHeaderBase } from '../tabs.base';
5
import { IgxTabsComponent } from './tabs.component';
6
import { getResizeObserver } from '../../core/utils';
7
import { PlatformUtil } from '../../core/utils';
8
import { IgxDirectionality } from '../../services/direction/directionality';
9

10
@Component({
11
    selector: 'igx-tab-header',
12
    templateUrl: 'tab-header.component.html',
13
    providers: [{ provide: IgxTabHeaderBase, useExisting: IgxTabHeaderComponent }],
14
    standalone: true
15
})
16
export class IgxTabHeaderComponent extends IgxTabHeaderDirective implements AfterViewInit, OnDestroy {
2✔
17

18
    /** @hidden @internal */
19
    @HostBinding('class.igx-tabs__header-item--selected')
20
    public get provideCssClassSelected(): boolean {
UNCOV
21
        return this.tab.selected;
×
22
    }
23

24
    /** @hidden @internal */
25
    @HostBinding('class.igx-tabs__header-item--disabled')
26
    public get provideCssClassDisabled(): boolean {
UNCOV
27
        return this.tab.disabled;
×
28
    }
29

30
    /** @hidden @internal */
31
    @HostBinding('class.igx-tabs__header-item')
UNCOV
32
    public cssClass = true;
×
33

34
    private _resizeObserver: ResizeObserver;
35

36
    /** @hidden @internal */
37
    constructor(
UNCOV
38
        protected override tabs: IgxTabsComponent,
×
39
        tab: IgxTabItemDirective,
40
        elementRef: ElementRef<HTMLElement>,
41
        platform: PlatformUtil,
UNCOV
42
        private ngZone: NgZone,
×
UNCOV
43
        private dir: IgxDirectionality
×
44
    ) {
UNCOV
45
        super(tabs, tab, elementRef, platform);
×
46
    }
47

48
    /** @hidden @internal */
49
    @HostListener('keydown', ['$event'])
50
    public keyDown(event: KeyboardEvent) {
UNCOV
51
        let unsupportedKey = false;
×
UNCOV
52
        const itemsArray = this.tabs.items.toArray();
×
UNCOV
53
        const previousIndex = itemsArray.indexOf(this.tab);
×
UNCOV
54
        let newIndex = previousIndex;
×
UNCOV
55
        const hasDisabledItems = itemsArray.some((item) => item.disabled);
×
56

UNCOV
57
        switch (event.key) {
×
58
            case this.platform.KEYMAP.ARROW_RIGHT:
UNCOV
59
                newIndex = this.getNewSelectionIndex(newIndex, itemsArray, event.key, hasDisabledItems);
×
UNCOV
60
                break;
×
61
            case this.platform.KEYMAP.ARROW_LEFT:
UNCOV
62
                newIndex = this.getNewSelectionIndex(newIndex, itemsArray, event.key, hasDisabledItems);
×
UNCOV
63
                break;
×
64
            case this.platform.KEYMAP.HOME:
UNCOV
65
                event.preventDefault();
×
UNCOV
66
                newIndex = 0;
×
UNCOV
67
                while (itemsArray[newIndex].disabled && newIndex < itemsArray.length) {
×
UNCOV
68
                    newIndex = newIndex === itemsArray.length - 1 ? 0 : newIndex + 1;
×
69
                }
UNCOV
70
                break;
×
71
            case this.platform.KEYMAP.END:
UNCOV
72
                event.preventDefault();
×
UNCOV
73
                newIndex = itemsArray.length - 1;
×
UNCOV
74
                while (hasDisabledItems && itemsArray[newIndex].disabled && newIndex > 0) {
×
UNCOV
75
                    newIndex = newIndex === 0 ? itemsArray.length - 1 : newIndex - 1;
×
76
                }
UNCOV
77
                break;
×
78
            case this.platform.KEYMAP.ENTER:
79
            case this.platform.KEYMAP.SPACE:
UNCOV
80
                event.preventDefault();
×
UNCOV
81
                if (this.tabs.activation === 'manual') {
×
UNCOV
82
                    this.nativeElement.click();
×
83
                }
UNCOV
84
                unsupportedKey = true;
×
UNCOV
85
                break;
×
86
            default:
87
                unsupportedKey = true;
×
88
                break;
×
89
        }
90

UNCOV
91
        if (!unsupportedKey) {
×
UNCOV
92
            itemsArray[newIndex].headerComponent.nativeElement.focus({ preventScroll: true });
×
UNCOV
93
            if (this.tabs.activation === 'auto') {
×
UNCOV
94
                this.tabs.selectedIndex = newIndex;
×
95
            }
96
        }
97
    }
98

99
    /** @hidden @internal */
100
    public ngAfterViewInit(): void {
UNCOV
101
        this.ngZone.runOutsideAngular(() => {
×
UNCOV
102
            if (this.platform.isBrowser) {
×
UNCOV
103
                this._resizeObserver = new (getResizeObserver())(() => {
×
UNCOV
104
                    this.tabs.realignSelectedIndicator();
×
105
                });
UNCOV
106
                this._resizeObserver.observe(this.nativeElement);
×
107
            }
108
        });
109
    }
110

111
    /** @hidden @internal */
112
    public ngOnDestroy(): void {
UNCOV
113
        this.ngZone.runOutsideAngular(() => {
×
UNCOV
114
            this._resizeObserver?.disconnect();
×
115
        });
116
    }
117

118
    private getNewSelectionIndex(newIndex: number, itemsArray: any[], key: string, hasDisabledItems: boolean): number {
UNCOV
119
        if ((key === this.platform.KEYMAP.ARROW_RIGHT && !this.dir.rtl) || (key === this.platform.KEYMAP.ARROW_LEFT && this.dir.rtl)) {
×
UNCOV
120
            newIndex = newIndex === itemsArray.length - 1 ? 0 : newIndex + 1;
×
UNCOV
121
            while (hasDisabledItems && itemsArray[newIndex].disabled && newIndex < itemsArray.length) {
×
UNCOV
122
                newIndex = newIndex === itemsArray.length - 1 ? 0 : newIndex + 1;
×
123
            }
124
        } else {
UNCOV
125
            newIndex = newIndex === 0 ? itemsArray.length - 1 : newIndex - 1;
×
UNCOV
126
            while (hasDisabledItems && itemsArray[newIndex].disabled && newIndex >= 0) {
×
UNCOV
127
                newIndex = newIndex === 0 ? itemsArray.length - 1 : newIndex - 1;
×
128
            }
129
        }
UNCOV
130
        return newIndex;
×
131
    }
132
}
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

© 2025 Coveralls, Inc