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

IgniteUI / igniteui-angular / 6797384210

08 Nov 2023 11:09AM UTC coverage: 91.853% (-0.3%) from 92.123%
6797384210

push

github

web-flow
Merge pull request #13613 from IgniteUI/mkirova/fix-empty-pivot

fix(igxPivotGrid): Add check in case data is empty due to removing al…

12459 of 14514 branches covered (0.0%)

1 of 1 new or added line in 1 file covered. (100.0%)

2127 existing lines in 217 files now uncovered.

25413 of 27667 relevant lines covered (91.85%)

31122.38 hits per line

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

98.18
/projects/igniteui-angular/src/lib/select/select-navigation.directive.ts
1
import { IgxDropDownItemNavigationDirective } from '../drop-down/drop-down-navigation.directive';
2
import { Directive, Input, OnDestroy } from '@angular/core';
3
import { Subscription, timer } from 'rxjs';
4
import { IgxSelectItemComponent } from './select-item.component';
5
import { IgxSelectBase } from './select.common';
6

7
/** @hidden @internal */
8
@Directive({
9
    selector: '[igxSelectItemNavigation]',
10
    standalone: true
11
})
12
export class IgxSelectItemNavigationDirective extends IgxDropDownItemNavigationDirective implements OnDestroy {
2✔
13
    protected override _target: IgxSelectBase = null;
474✔
14

15
    @Input('igxSelectItemNavigation')
16
    public override get target(): IgxSelectBase {
17
        return this._target;
711✔
18
    }
19
    public override set target(target: IgxSelectBase) {
20
        this._target = target ? target : this.dropdown as IgxSelectBase;
474!
21
    }
22

23
    constructor() {
24
        super(null);
474✔
25
    }
26

27
    /** Captures keydown events and calls the appropriate handlers on the target component */
28
    public override handleKeyDown(event: KeyboardEvent) {
29
        if (!event) {
177!
UNCOV
30
            return;
×
31
        }
32

33
        const key = event.key.toLowerCase();
177✔
34
        if (event.altKey && (key === 'arrowdown' || key === 'arrowup' || key === 'down' || key === 'up')) {
177!
35
            this.target.toggle();
7✔
36
            return;
7✔
37
        }
38

39
        if (this.target.collapsed) {
170✔
40
            switch (key) {
68✔
41
                case 'space':
42
                case 'spacebar':
43
                case ' ':
44
                case 'enter':
45
                    event.preventDefault();
4✔
46
                    this.target.open();
4✔
47
                    return;
4✔
48
                case 'arrowdown':
49
                case 'down':
50
                    this.target.navigateNext();
23✔
51
                    this.target.selectItem(this.target.focusedItem);
23✔
52
                    event.preventDefault();
23✔
53
                    return;
23✔
54
                case 'arrowup':
55
                case 'up':
56
                    this.target.navigatePrev();
20✔
57
                    this.target.selectItem(this.target.focusedItem);
20✔
58
                    event.preventDefault();
20✔
59
                    return;
20✔
60
                default:
61
                    break;
21✔
62
            }
63
        } else if (key === 'tab' || event.shiftKey && key === 'tab') {
102!
64
            this.target.close();
2✔
65
        }
66

67
        super.handleKeyDown(event);
123✔
68
        this.captureKey(event);
123✔
69
    }
70

71
    /* eslint-disable @typescript-eslint/member-ordering */
72
    private inputStream = '';
474✔
73
    private clearStream$ = Subscription.EMPTY;
474✔
74

75
    public captureKey(event: KeyboardEvent) {
76
        // relying only on key, available on all major browsers:
77
        // https://caniuse.com/#feat=keyboardevent-key (IE/Edge quirk doesn't affect letter typing)
78
        if (!event || !event.key || event.key.length > 1 || event.key === ' ' || event.key === 'spacebar') {
123✔
79
            // ignore longer keys ('Alt', 'ArrowDown', etc) AND spacebar (used of open/close)
80
            return;
82✔
81
        }
82

83
        this.clearStream$.unsubscribe();
41✔
84
        this.clearStream$ = timer(500).subscribe(() => {
41✔
85
            this.inputStream = '';
27✔
86
        });
87

88
        this.inputStream += event.key;
41✔
89
        const focusedItem = this.target.focusedItem as IgxSelectItemComponent;
41✔
90

91
        // select the item
92
        if (focusedItem && this.inputStream.length > 1 && focusedItem.itemText.toLowerCase().startsWith(this.inputStream.toLowerCase())) {
41✔
93
            return;
6✔
94
        }
95
        this.activateItemByText(this.inputStream);
35✔
96
    }
97

98
    public activateItemByText(text: string) {
99
        const items = this.target.items as IgxSelectItemComponent[];
35✔
100

101
        // ^ this is focused OR selected if the dd is closed
102

103
        let nextItem = this.findNextItem(items, text);
35✔
104

105
        // If there is no such an item starting with the current text input stream AND the last Char in the input stream
106
        // is the same as the first one, find next item starting with the same first Char.
107
        // Covers cases of holding down the same key Ex: "pppppp" that iterates trough list items starting with "p".
108
        if (!nextItem && text.charAt(0) === text.charAt(text.length - 1)) {
35✔
109
            text = text.slice(0, 1);
2✔
110
            nextItem = this.findNextItem(items, text);
2✔
111
        }
112

113
        // If there is no other item to be found, do not change the active item.
114
        if (!nextItem) {
35✔
115
            return;
2✔
116
        }
117

118
        if (this.target.collapsed) {
33✔
119
            this.target.selectItem(nextItem);
17✔
120
        }
121
        this.target.navigateItem(items.indexOf(nextItem));
33✔
122
    }
123

124
    public ngOnDestroy(): void {
125
        this.clearStream$.unsubscribe();
474✔
126
    }
127

128
    private findNextItem(items: IgxSelectItemComponent[],  text: string) {
129
        const activeItemIndex = items.indexOf(this.target.focusedItem as IgxSelectItemComponent) || 0;
37✔
130

131
        // Match next item in ddl items and wrap around if needed
132
        return items.slice(activeItemIndex + 1).find(x => !x.disabled && (x.itemText.toLowerCase().startsWith(text.toLowerCase()))) ||
165✔
133
            items.slice(0, activeItemIndex).find(x => !x.disabled && (x.itemText.toLowerCase().startsWith(text.toLowerCase())));
44✔
134
    }
135
}
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