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

atinc / ngx-tethys / #55

30 Jul 2025 07:08AM UTC coverage: 9.866% (-80.4%) from 90.297%
#55

push

why520crazy
feat(empty): add setMessage for update display text #TINFR-2616

92 of 6794 branches covered (1.35%)

Branch coverage included in aggregate %.

2014 of 14552 relevant lines covered (13.84%)

6.15 hits per line

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

10.81
/src/upload/file-select.component.ts
1
import { fromEvent } from 'rxjs';
2
import { Component, ElementRef, NgZone, inject, Inject, viewChild, output, input, DestroyRef, effect } from '@angular/core';
3
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
import { FileSelectBaseDirective } from './file-select-base';
5
import { THY_UPLOAD_DEFAULT_OPTIONS, ThyUploadConfig } from './upload.config';
6
import { coerceBooleanProperty } from 'ngx-tethys/util';
7
import { ThyFileSelectEvent } from './types';
8

9
/**
10
 * 文件上传组件
11
 * @name thy-file-select,[thyFileSelect]
12
 * @order 10
13
 */
14
@Component({
15
    selector: '[thyFileSelect],thy-file-select',
1✔
16
    templateUrl: './file-select.component.html'
17
})
×
18
export class ThyFileSelect extends FileSelectBaseDirective {
×
19
    /**
×
20
     * 文件选择事件
×
21
     */
×
22
    readonly thyOnFileSelect = output<ThyFileSelectEvent>();
×
23

×
24
    protected readonly fileInput = viewChild<ElementRef<HTMLInputElement>>('fileInput');
×
25

×
26
    /**
×
27
     * 文件是否多选
28
     * @default false
29
     */
×
30
    readonly thyMultiple = input(false, { transform: coerceBooleanProperty });
31

×
32
    /**
×
33
     * 是否接受文件夹
×
34
     */
×
35
    readonly thyAcceptFolder = input(false, { transform: coerceBooleanProperty });
×
36

×
37
    private destroyRef = inject(DestroyRef);
38

39
    constructor(
×
40
        public elementRef: ElementRef,
41
        @Inject(THY_UPLOAD_DEFAULT_OPTIONS) public defaultConfig: ThyUploadConfig,
×
42
        private ngZone: NgZone
×
43
    ) {
44
        super(elementRef, defaultConfig);
45

×
46
        this.ngZone.runOutsideAngular(() =>
47
            fromEvent(this.elementRef.nativeElement, 'click')
48
                .pipe(takeUntilDestroyed(this.destroyRef))
49
                .subscribe(() => {
50
                    this.fileInput().nativeElement.click();
×
51
                })
×
52
        );
×
53

×
54
        effect(() => {
55
            const multiple = this.thyMultiple();
56
            const acceptFolder = this.thyAcceptFolder();
1✔
57
            const inputElement = this.fileInput().nativeElement;
58
            if (multiple) {
59
                inputElement.setAttribute('multiple', '');
60
            } else {
61
                inputElement.removeAttribute('multiple');
1✔
62
            }
63
            if (acceptFolder) {
64
                inputElement.setAttribute('webkitdirectory', '');
65
            } else {
66
                inputElement.removeAttribute('webkitdirectory');
67
            }
68
        });
1✔
69
    }
70

71
    selectFile($event: Event) {
72
        const files = this.fileInput().nativeElement.files;
73
        if (files && files.length > 0) {
74
            this.selectFiles($event, Array.from(files), this.thyOnFileSelect);
75
            this.fileInput().nativeElement.value = '';
76
        }
77
    }
78
}
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