• 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

70.45
/src/stepper/stepper.component.ts
1
import {
2
    Component,
3
    numberAttribute,
4
    viewChildren,
5
    output,
6
    contentChildren,
7
    input,
8
    computed,
9
    effect,
10
    ChangeDetectionStrategy,
11
    signal,
12
    untracked
13
} from '@angular/core';
14
import { ThyStep, IThyStepperComponent, THY_STEPPER_COMPONENT } from './step.component';
1✔
15
import { ThyStepHeader } from './step-header.component';
16
import { NgTemplateOutlet } from '@angular/common';
1✔
17
import { coerceBooleanProperty } from 'ngx-tethys/util';
1✔
18

1✔
19
/**
1✔
20
 * 步骤条组件
1✔
21
 * @name thy-stepper
1✔
22
 * @order 10
1✔
23
 */
1✔
24
@Component({
1✔
25
    selector: 'thy-stepper',
1!
26
    templateUrl: 'stepper.component.html',
×
27
    providers: [{ provide: THY_STEPPER_COMPONENT, useExisting: ThyStepper }],
×
28
    imports: [ThyStepHeader, NgTemplateOutlet],
29
    changeDetection: ChangeDetectionStrategy.OnPush,
30
    host: { class: 'thy-stepper' }
31
})
1✔
32
export class ThyStepper implements IThyStepperComponent {
1✔
33
    /**
1!
34
     * 当前处于激活状态的步骤 index
1✔
35
     */
1✔
36
    readonly thySelectedIndex = input<number, unknown>(0, { transform: numberAttribute });
1!
37

1✔
38
    /**
39
     * 当前处于激活状态的步骤实例
40
     */
41
    readonly thySelected = input<ThyStep>();
42

43
    /**
44
     * 步骤条导航是否展示,默认展示
1!
45
     */
×
46
    readonly thyShowStepHeader = input(true, { transform: coerceBooleanProperty });
47

1✔
48
    readonly selectionChange = output<any>();
1!
49

1✔
50
    readonly steps = contentChildren(ThyStep);
1✔
51

52
    readonly selectedIndex = signal(0);
53

54
    protected readonly selected = computed(() => this.steps()?.[this.selectedIndex()]);
55

56
    constructor() {
57
        effect(() => {
58
            const newIndex = this.thySelectedIndex();
×
59
            if (newIndex) {
×
60
                untracked(() => {
61
                    this.updateSelectedIndex(newIndex);
62
                });
×
63
            }
64
        });
65

×
66
        effect(() => {
67
            const selected = this.thySelected();
68
            if (selected) {
69
                untracked(() => {
×
70
                    const index = this.steps()?.indexOf(selected);
71
                    if (index > -1) {
1✔
72
                        this.updateSelectedIndex(index);
1✔
73
                    }
74
                });
75
            }
76
        });
77
    }
78

79
    private updateSelectedIndex(newIndex: number): void {
80
        if (!this.steps()?.[newIndex]) {
1✔
81
            return;
82
        }
83
        const previouslySelectedIndex = this.selectedIndex();
84
        const previouslySelectedStep = this.steps() ? this.steps()[previouslySelectedIndex] : null;
85
        this.selectedIndex.set(newIndex);
86
        this.selectionChange.emit({
87
            selectedIndex: newIndex,
88
            previouslySelectedIndex: previouslySelectedIndex,
89
            selectedStep: this.selected(),
90
            previouslySelectedStep: previouslySelectedStep
91
        });
92
    }
93

94
    updateSelected(step: ThyStep): void {
95
        const index = this.steps().indexOf(step);
96
        this.updateSelectedIndex(index);
97
    }
98

99
    to(index: number): void {
100
        this.updateSelectedIndex(Math.min(index, this.steps().length - 1));
101
    }
102

103
    next(): void {
104
        this.updateSelectedIndex(Math.min(this.selectedIndex() + 1, this.steps().length - 1));
105
    }
106

107
    /** Selects and focuses the previous step in list. */
108
    previous(): void {
109
        this.updateSelectedIndex(Math.max(this.selectedIndex() - 1, 0));
110
    }
111
}
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