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

atinc / ngx-tethys / e62d3b10-1466-49c3-aabd-707148681fc8

14 Jun 2024 08:24AM UTC coverage: 90.422%. Remained the same
e62d3b10-1466-49c3-aabd-707148681fc8

push

circleci

minlovehua
feat: use the ngx-tethys/util's coerceBooleanProperty instead of booleanAttribute #INFR-12648

5467 of 6692 branches covered (81.69%)

Branch coverage included in aggregate %.

117 of 120 new or added lines in 66 files covered. (97.5%)

183 existing lines in 46 files now uncovered.

13216 of 13970 relevant lines covered (94.6%)

985.91 hits per line

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

90.63
/src/nav/nav-item.directive.ts
1
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2
import { useHostRenderer } from '@tethys/cdk/dom';
3
import {
4
    AfterViewInit,
5
    ContentChildren,
6
    DestroyRef,
7
    Directive,
8
    ElementRef,
9
    forwardRef,
10
    inject,
11
    Input,
12
    NgZone,
1✔
13
    Optional,
14
    QueryList
158✔
15
} from '@angular/core';
158✔
16
import { RouterLinkActive } from '@angular/router';
158✔
17
import { coerceBooleanProperty } from 'ngx-tethys/util';
18

158✔
19
export type ThyNavLink = '' | 'active';
20

21
/**
22
 * 导航项
23
 * @name thyNavItem
24
 * @order 20
158✔
25
 */
158✔
26
@Directive({
27
    selector: '[thyNavLink],[thyNavItem]',
28
    host: {
158✔
29
        class: 'thy-nav-item',
158✔
30
        '[class.active]': 'thyNavItemActive || thyNavLinkActive',
158✔
31
        '[class.disabled]': 'thyNavItemDisabled'
574✔
32
    },
33
    standalone: true
34
})
35
export class ThyNavItemDirective implements AfterViewInit {
179✔
36
    /**
37
     * 是否激活状态
38
     * @default false
39
     */
40
    @Input({ transform: coerceBooleanProperty })
41
    thyNavItemActive: boolean;
42

43
    /**
943✔
44
     * 已经废弃,请使用 thyNavItemActive
45
     * @deprecated please use thyNavItemActive
46
     * @default false
×
47
     */
×
NEW
48
    @Input({ transform: coerceBooleanProperty })
×
49
    thyNavLinkActive: boolean;
50

51
    /**
28✔
52
     * 是否禁用
21✔
53
     * @default false
54
     */
55
    @Input({ transform: coerceBooleanProperty })
7✔
56
    thyNavItemDisabled: boolean;
57

58
    /**
1✔
59
     * @private
60
     */
61
    @ContentChildren(forwardRef(() => ThyNavItemDirective), { descendants: true })
62
    links: QueryList<ThyNavItemDirective>;
63

1✔
64
    /**
65
     * @private
66
     */
67
    @ContentChildren(RouterLinkActive, { descendants: true }) routers: QueryList<RouterLinkActive>;
2✔
68

69
    // @HostBinding('attr.href') navLinkHref = 'javascript:;';
70

71
    public offset: {
1✔
72
        width: number;
73
        height: number;
74
        left: number;
75
        top: number;
76
    } = {
77
        width: 0,
78
        height: 0,
79
        left: 0,
80
        top: 0
81
    };
82

83
    public content: HTMLElement;
84

85
    public isActive: boolean;
86

87
    private hostRenderer = useHostRenderer();
88

89
    private readonly destroyRef = inject(DestroyRef);
90

91
    constructor(public elementRef: ElementRef, @Optional() private routerLinkActive: RouterLinkActive, private ngZone: NgZone) {}
92

93
    ngAfterViewInit() {
94
        this.setOffset();
95

96
        this.content = this.elementRef.nativeElement.outerHTML;
97

98
        this.ngZone.onStable.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
99
            this.isActive = this.linkIsActive();
100
        });
101
    }
102

103
    setOffset() {
104
        this.offset = {
105
            width: this.elementRef.nativeElement.offsetWidth,
106
            height: this.elementRef.nativeElement.offsetHeight,
107
            left: this.elementRef.nativeElement.offsetLeft,
108
            top: this.elementRef.nativeElement.offsetTop
109
        };
110
    }
111

112
    linkIsActive() {
113
        return (
114
            this.thyNavItemActive ||
115
            this.thyNavLinkActive ||
116
            (this.routerLinkActive && this.routerLinkActive.isActive) ||
117
            this.routers.some(router => router.isActive) ||
118
            this.links.some(item => item.thyNavItemActive) ||
119
            this.links.some(item => item.thyNavLinkActive)
120
        );
121
    }
122

123
    setNavLinkHidden(value: boolean) {
124
        if (value) {
125
            this.hostRenderer.addClass('thy-nav-item-hidden');
126
        } else {
127
            this.hostRenderer.removeClass('thy-nav-item-hidden');
128
        }
129
    }
130
}
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