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

atinc / ngx-tethys / 826be5f3-7786-4086-adc2-e69fc703edb5

22 Aug 2023 12:45AM UTC coverage: 90.108%. Remained the same
826be5f3-7786-4086-adc2-e69fc703edb5

Pull #2788

circleci

minlovehua
feat(input): manage input-search focus #INFR-8466, and adjust input-number focus monitor #INFR-8467
Pull Request #2788: feat(input): manage input-search focus #INFR-8466, and adjust input-number focus monitor #INFR-8467

5086 of 6299 branches covered (80.74%)

Branch coverage included in aggregate %.

31 of 31 new or added lines in 3 files covered. (100.0%)

12841 of 13596 relevant lines covered (94.45%)

979.05 hits per line

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

88.89
/src/input/input-group.component.ts
1
import {
2
    Component,
3
    HostBinding,
4
    Input,
5
    ContentChild,
6
    TemplateRef,
7
    ViewEncapsulation,
8
    ChangeDetectionStrategy,
1✔
9
    AfterContentChecked,
10
    OnInit,
11
    OnDestroy
12
} from '@angular/core';
13
import { MixinBase, ThyTranslate, mixinUnsubscribe, useHostFocusControl } from 'ngx-tethys/core';
14
import { useHostRenderer } from '@tethys/cdk/dom';
15
import { ThyInputDirective } from './input.directive';
16
import { NgIf, NgTemplateOutlet } from '@angular/common';
17
import { FocusOrigin } from '@angular/cdk/a11y';
18

1✔
19
export type InputGroupSize = 'sm' | 'lg' | 'md' | '';
20

8✔
21
const inputGroupSizeMap = {
22
    sm: ['input-group-sm'],
23
    lg: ['input-group-lg'],
8!
24
    md: ['input-group-md']
8✔
25
};
26

27
/**
28
 * 输入框分组
8✔
29
 * @name thy-input-group
30
 * @order 20
31
 */
8!
32
@Component({
8✔
33
    selector: 'thy-input-group',
34
    templateUrl: './input-group.component.html',
35
    changeDetection: ChangeDetectionStrategy.OnPush,
36
    encapsulation: ViewEncapsulation.None,
18✔
37
    host: {
3✔
38
        class: 'thy-input-group',
39
        '[class.form-control]': 'prefixTemplate || suffixTemplate',
40
        '[class.thy-input-group-with-prefix]': 'prefixTemplate',
15✔
41
        '[class.thy-input-group-with-suffix]': 'suffixTemplate'
42
    },
43
    standalone: true,
44
    imports: [NgIf, NgTemplateOutlet]
28✔
45
})
28✔
46
export class ThyInputGroupComponent extends mixinUnsubscribe(MixinBase) implements OnInit, AfterContentChecked, OnDestroy {
28✔
47
    private hostRenderer = useHostRenderer();
28✔
48

28✔
49
    private hostFocusControl = useHostFocusControl();
50

51
    public appendText: string;
28✔
52

2!
53
    public prependText: string;
2✔
54

55
    @HostBinding('class.disabled') disabled = false;
56

×
57
    /**
58
     * 输入框上添加的后置文本
59
     */
60
    @Input()
61
    set thyAppendText(value: string) {
43✔
62
        this.appendText = value;
63
    }
64

28✔
65
    /**
28✔
66
     * 输入框上添加的后置文本多语言 Key
67
     */
1✔
68
    @Input()
69
    set thyAppendTextTranslateKey(value: string) {
70
        if (value) {
1✔
71
            this.appendText = this.thyTranslate.instant(value);
72
        }
73
    }
74

75
    /**
76
     * 输入框上添加的前置文本
77
     */
78
    @Input()
79
    set thyPrependText(value: string) {
80
        this.prependText = value;
81
    }
82

83
    /**
84
     * 输入框上添加的前置文本多语言 Key
1✔
85
     */
86
    @Input()
87
    set thyPrependTextTranslateKey(value: string) {
88
        if (value) {
89
            this.prependText = this.thyTranslate.instant(value);
90
        }
91
    }
92

93
    /**
94
     * 输入框分组大小
95
     * @type 'sm' | 'lg' | 'md' | ''
96
     * @default ''
97
     */
98
    @Input()
99
    set thySize(size: InputGroupSize) {
100
        if (size && inputGroupSizeMap[size]) {
101
            this.hostRenderer.updateClass(inputGroupSizeMap[size]);
102
        } else {
103
            this.hostRenderer.updateClass([]);
104
        }
105
    }
106

107
    /**
108
     * 后置模板
109
     */
110
    @ContentChild('append') appendTemplate: TemplateRef<unknown>;
111

112
    /**
113
     * 前置模板
114
     */
115
    @ContentChild('prepend') prependTemplate: TemplateRef<unknown>;
116

117
    /**
118
     * 前缀
119
     */
120
    @ContentChild('prefix') prefixTemplate: TemplateRef<unknown>;
121

122
    /**
123
     * 后缀
124
     */
125
    @ContentChild('suffix') suffixTemplate: TemplateRef<unknown>;
126

127
    /**
128
     * @private
129
     */
130
    @ContentChild(ThyInputDirective) inputDirective: ThyInputDirective;
131

132
    constructor(private thyTranslate: ThyTranslate) {
133
        super();
134
    }
135

136
    ngOnInit() {
137
        this.hostFocusControl.focusChanged = (origin: FocusOrigin) => {
138
            if (origin) {
139
                this.hostRenderer.addClass('form-control-active');
140
            } else {
141
                this.hostRenderer.removeClass('form-control-active');
142
            }
143
        };
144
    }
145

146
    ngAfterContentChecked(): void {
147
        this.disabled = !!this.inputDirective?.nativeElement?.hasAttribute('disabled');
148
    }
149

150
    ngOnDestroy() {
151
        super.ngOnDestroy();
152
        this.hostFocusControl.destroy();
153
    }
154
}
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