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

atinc / ngx-tethys / 3b40a702-4b4d-4ddb-81a7-a96baae6d682

08 Nov 2024 05:40AM UTC coverage: 90.395% (-0.04%) from 90.431%
3b40a702-4b4d-4ddb-81a7-a96baae6d682

push

circleci

why520crazy
Merge branch 'master' into feat-theme

5503 of 6730 branches covered (81.77%)

Branch coverage included in aggregate %.

424 of 431 new or added lines in 171 files covered. (98.38%)

344 existing lines in 81 files now uncovered.

13150 of 13905 relevant lines covered (94.57%)

999.86 hits per line

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

88.24
/src/tooltip/tooltip.directive.ts
1
import { FocusMonitor } from '@angular/cdk/a11y';
2
import { Platform } from '@angular/cdk/platform';
3
import { Directive, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewContainerRef, numberAttribute, inject } from '@angular/core';
4
import { ThyOverlayDirectiveBase, ThyOverlayTrigger, ThyPlacement } from 'ngx-tethys/core';
5
import { SafeAny } from 'ngx-tethys/types';
6
import { coerceBooleanProperty, isString } from 'ngx-tethys/util';
7
import { ThyTooltipContent } from './interface';
8
import { ThyTooltipRef } from './tooltip-ref';
9
import { ThyTooltipService } from './tooltip.service';
10

11
/**
1✔
12
 * @name thyTooltip
13
 */
31✔
14
@Directive({
15
    selector: '[thyTooltip],[thy-tooltip]',
16
    exportAs: 'thyTooltip',
17
    standalone: true
2,720✔
18
})
2,720!
19
export class ThyTooltipDirective extends ThyOverlayDirectiveBase implements OnInit, OnDestroy {
×
20
    private viewContainerRef = inject(ViewContainerRef);
21
    private thyTooltipService = inject(ThyTooltipService);
22

2,720✔
23
    touchendHideDelay = 1500;
24

25
    protected isAutoCloseOnMobileTouch: boolean = true;
UNCOV
26

×
UNCOV
27
    private tooltipClass: string | string[];
×
28

29
    private tooltipRef: ThyTooltipRef;
30

×
31
    private _content: ThyTooltipContent;
32

33
    get content() {
1,307✔
34
        return this._content;
35
    }
1,307✔
36

1,243✔
37
    /**
38
     * 提示消息,可以是文本,也可以是一个模板
39
     * @type string | TemplateRef<T>
UNCOV
40
     */
×
41
    @Input('thyTooltip') set content(value: ThyTooltipContent) {
42
        // If the content is not a string (e.g. number), convert it to a string and trim it.
43
        this._content = value && isString(value) ? `${value}`.trim() : value;
1,531✔
44
        if (!this._content && this.tooltipRef?.isTooltipVisible()) {
1,531✔
45
            this.tooltipRef.hide(0);
1,531✔
46
        } else {
1,531✔
47
            this.tooltipRef?.updateTooltipContent(value, this.data);
1,531✔
48
        }
1,531✔
49
    }
1,531✔
50

1,531✔
51
    /**
1,531✔
52
     * 指定提示的位置
1,531✔
53
     * @type ThyPlacement
1,531✔
54
     */
55
    @Input('thyTooltipPlacement') placement: ThyPlacement = 'top';
56

1,531✔
57
    /**
58
     * 提示内容自定义样式
59
     */
16✔
60
    @Input('thyTooltipClass')
30✔
61
    set thyTooltipClass(value: string | string[]) {
3✔
62
        this.tooltipClass = value;
63
        this.tooltipRef?.setTooltipClass(this.tooltipClass);
27✔
64
    }
23✔
65

66
    /**
67
     * 显示提示内容延迟毫秒
68
     */
69
    @Input({ alias: 'thyTooltipShowDelay', transform: numberAttribute }) showDelay: number;
70

71
    /**
72
     * 隐藏提示内容延迟毫秒
73
     */
27✔
74
    @Input({ alias: 'thyTooltipHideDelay', transform: numberAttribute }) hideDelay: number;
75

76
    _trigger: ThyOverlayTrigger = 'hover';
1,192✔
77

2,438✔
78
    /**
79
     * 触发提示方式
80
     * <br/>`hover` 鼠标移入,显示提示;鼠标移出,隐藏提示;显示提示时,滚动页面,会隐藏提示。
1,532✔
81
     * <br/>`focus` 元素获取焦点,显示提示;元素失去焦点,隐藏提示;显示元素时,滚动页面,提示会跟随聚焦源一起移动。
82
     * <br/>`click` 点击元素,显示提示;点击backdrop,隐藏提示;显示提示时,页面的滚动行为会被阻止。
1✔
83
     *
1✔
84
     * @type hover | focus | click
85
     */
86
    @Input('thyTooltipTrigger') set thyTooltipTrigger(value: ThyOverlayTrigger) {
87
        this.trigger = value;
88
    }
89

90
    /**
91
     * 设置是否禁用提示
92
     * @default false
93
     */
94
    @Input({ alias: 'thyTooltipDisabled', transform: coerceBooleanProperty })
95
    set thyTooltipDisabled(value: boolean) {
96
        this.disabled = value;
1✔
97
        // If tooltip is disabled, hide immediately.
98
        if (this.disabled) {
99
            this.hide(0);
100
        }
101
    }
102

103
    /**
104
     * 传入 template 时,需要注入给 template 的上下文数据
105
     */
106
    @Input('thyTooltipTemplateContext') data: SafeAny;
107

108
    /**
109
     * 偏移量
110
     */
111
    @Input({ alias: 'thyTooltipOffset', transform: numberAttribute }) tooltipOffset: number;
112

113
    /**
114
     * hover 触发方式下 鼠标移入Tooltip是否固定 Tooltip
115
     * @default false
116
     */
117
    @Input({ alias: 'thyTooltipPin', transform: coerceBooleanProperty })
118
    set tooltipPin(value: boolean) {
119
        this.overlayPin = value;
120
    }
121

122
    constructor() {
123
        const elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
124
        const ngZone = inject(NgZone);
125
        const platform = inject(Platform);
126
        const focusMonitor = inject(FocusMonitor);
127

128
        super(elementRef, platform, focusMonitor, ngZone);
129
    }
130

131
    ngOnInit() {
132
        this.initialize();
133
    }
134

135
    /** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show 200ms */
136
    show(delay: number = this.showDelay): void {
137
        if (this.disabled) {
138
            return;
139
        }
140
        if (!this.tooltipRef) {
141
            this.tooltipRef = this.thyTooltipService.create(this.elementRef, {
142
                viewContainerRef: this.viewContainerRef,
143
                placement: this.placement,
144
                contentClass: this.tooltipClass,
145
                offset: this.tooltipOffset,
146
                tooltipPin: this.tooltipPin,
147
                hasBackdrop: this.trigger === 'click'
148
            });
149
        }
150
        this.tooltipRef.show(this.content, this.data, delay);
151
    }
152

153
    /** Hides the tooltip after the delay in ms, defaults to tooltip-delay-hide 100ms */
154
    hide(delay: number = this.hideDelay): void {
155
        this.tooltipRef?.hide(delay);
156
    }
157

158
    ngOnDestroy() {
159
        this.tooltipRef?.dispose();
160
    }
161
}
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