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

Raiper34 / ngx-focus-control / 295baa8b-6e06-4564-af93-07616a108d32

01 Apr 2024 06:33PM CUT coverage: 100.0%. Remained the same
295baa8b-6e06-4564-af93-07616a108d32

push

circleci

Raiper34
docs(readme): add focus unleavable directive into README.md

78 of 78 branches covered (100.0%)

Branch coverage included in aggregate %.

196 of 196 relevant lines covered (100.0%)

12.29 hits per line

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

100.0
/projects/ngx-focus-control/src/lib/directives/focus-selector.directive.ts
1
import {Directive, ElementRef, HostListener, Inject, Input} from '@angular/core';
2
import {DOCUMENT} from '@angular/common';
3
import {Keys} from '../helpers/keys.enum';
4

5
@Directive({
6
  selector: '[fuSelector]'
7
})
8
export class FocusSelectorDirective {
1✔
9

10
  @Input('fuSelector') selector: string;
11

12
  constructor(@Inject(DOCUMENT) private readonly document: any,
11✔
13
              private readonly el: ElementRef) {
11✔
14
  }
15

16
  @HostListener(`keydown`, ['$event']) goTo($event: KeyboardEvent) {
17
    if ($event.key === Keys.Tab) {
4✔
18
      const elements = Array.from(this.document.querySelectorAll(this.selector));
3✔
19
      const index = elements.findIndex(item => item === this.el.nativeElement);
5✔
20
      if ($event.shiftKey && index > 0) {
3✔
21
        $event.preventDefault();
1✔
22
        $event.stopPropagation();
1✔
23
        (elements[index - 1] as HTMLElement).focus();
1✔
24
      } else if (!$event.shiftKey && index < elements.length - 1) {
2✔
25
        $event.preventDefault();
1✔
26
        $event.stopPropagation();
1✔
27
        (elements[index + 1] as HTMLElement).focus();
1✔
28
      }
29
    }
30
  }
31

32
}
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