• 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

11.76
/projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts
1
import { Directive, Optional, Self, Input, HostListener, Inject } from '@angular/core';
2
import { IGX_DROPDOWN_BASE } from './drop-down.common';
3
import { IDropDownNavigationDirective } from './drop-down.common';
4
import { IgxDropDownBaseDirective } from './drop-down.base';
5
import { DropDownActionKey } from './drop-down.common';
6

7
/**
8
 * Navigation Directive that handles keyboard events on its host and controls a targeted IgxDropDownBaseDirective component
9
 */
10
@Directive({
11
    selector: '[igxDropDownItemNavigation]',
12
    standalone: true
13
})
14
export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDirective {
2✔
15

16
    protected _target: IgxDropDownBaseDirective = null;
183✔
17

18
    constructor(@Self() @Optional() @Inject(IGX_DROPDOWN_BASE) public dropdown: IgxDropDownBaseDirective) { }
183✔
19

20
    /**
21
     * Gets the target of the navigation directive;
22
     *
23
     * ```typescript
24
     * // Get
25
     * export class MyComponent {
26
     *  ...
27
     *  @ContentChild(IgxDropDownNavigationDirective)
28
     *  navDirective: IgxDropDownNavigationDirective = null
29
     *  ...
30
     *  const navTarget: IgxDropDownBaseDirective = navDirective.navTarget
31
     * }
32
     * ```
33
     */
34
     public get target(): IgxDropDownBaseDirective {
UNCOV
35
        return this._target;
×
36
    }
37

38
    /**
39
     * Sets the target of the navigation directive;
40
     * If no valid target is passed, it falls back to the drop down context
41
     *
42
     * ```html
43
     * <!-- Set -->
44
     * <input [igxDropDownItemNavigation]="dropdown" />
45
     * ...
46
     * <igx-drop-down #dropdown>
47
     * ...
48
     * </igx-drop-down>
49
     * ```
50
     */
51
    @Input('igxDropDownItemNavigation')
52
    public set target(target: IgxDropDownBaseDirective) {
53
        this._target = target ? target : this.dropdown;
89!
54
    }
55

56
    /**
57
     * Captures keydown events and calls the appropriate handlers on the target component
58
     */
59
    @HostListener('keydown', ['$event'])
60
    public handleKeyDown(event: KeyboardEvent) {
UNCOV
61
        if (event) {
×
UNCOV
62
            const key = event.key.toLowerCase();
×
UNCOV
63
            if (!this.target.collapsed) { // If dropdown is opened
×
UNCOV
64
                const navKeys = ['esc', 'escape', 'enter', 'space', 'spacebar', ' ',
×
65
            'arrowup', 'up', 'arrowdown', 'down', 'home', 'end'];
UNCOV
66
                if (navKeys.indexOf(key) === -1) { // If key has appropriate function in DD
×
UNCOV
67
                    return;
×
68
                }
UNCOV
69
                event.preventDefault();
×
UNCOV
70
                event.stopPropagation();
×
71
            } else { // If dropdown is closed, do nothing
UNCOV
72
                return;
×
73
            }
UNCOV
74
            switch (key) {
×
75
                case 'esc':
76
                case 'escape':
UNCOV
77
                    this.target.onItemActionKey(DropDownActionKey.ESCAPE, event);
×
UNCOV
78
                    break;
×
79
                case 'enter':
UNCOV
80
                    this.target.onItemActionKey(DropDownActionKey.ENTER, event);
×
UNCOV
81
                    break;
×
82
                case 'space':
83
                case 'spacebar':
84
                case ' ':
UNCOV
85
                    this.target.onItemActionKey(DropDownActionKey.SPACE, event);
×
UNCOV
86
                    break;
×
87
                case 'arrowup':
88
                case 'up':
UNCOV
89
                    this.onArrowUpKeyDown();
×
UNCOV
90
                    break;
×
91
                case 'arrowdown':
92
                case 'down':
UNCOV
93
                    this.onArrowDownKeyDown();
×
UNCOV
94
                    break;
×
95
                case 'home':
UNCOV
96
                    this.onHomeKeyDown();
×
UNCOV
97
                    break;
×
98
                case 'end':
UNCOV
99
                    this.onEndKeyDown();
×
UNCOV
100
                    break;
×
101
                default:
102
                    return;
×
103
            }
104
        }
105
    }
106

107
    /**
108
     * Navigates to previous item
109
     */
110
     public onArrowDownKeyDown() {
UNCOV
111
        this.target.navigateNext();
×
112
    }
113

114
    /**
115
     * Navigates to previous item
116
     */
117
     public onArrowUpKeyDown() {
UNCOV
118
        this.target.navigatePrev();
×
119
    }
120

121
    /**
122
     * Navigates to target's last item
123
     */
124
     public onEndKeyDown() {
UNCOV
125
        this.target.navigateLast();
×
126
    }
127

128
    /**
129
     * Navigates to target's first item
130
     */
131
     public onHomeKeyDown() {
UNCOV
132
        this.target.navigateFirst();
×
133
    }
134
}
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