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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

66.67
/projects/igniteui-angular/src/lib/directives/button/button.directive.ts
1
import {
2
    Directive,
3
    ElementRef,
4
    EventEmitter,
5
    HostBinding,
6
    Input,
7
    Output,
8
    Renderer2,
9
    booleanAttribute,
10
    AfterContentInit,
11
    OnDestroy
12
} from '@angular/core';
13
import { mkenum } from '../../core/utils';
14
import { IBaseEventArgs } from '../../core/utils';
15
import { IgxBaseButtonType, IgxButtonBaseDirective } from './button-base';
16

17
const IgxButtonType = /*@__PURE__*/mkenum({
2✔
18
    ...IgxBaseButtonType,
19
    FAB: 'fab'
20
});
21

22
/**
23
 * Determines the Button type.
24
 */
25
export type IgxButtonType = typeof IgxButtonType[keyof typeof IgxButtonType];
26

27
/**
28
 * The Button directive provides the Ignite UI Button functionality to every component that's intended to be used as a button.
29
 *
30
 * @igxModule IgxButtonModule
31
 *
32
 * @igxParent Data Entry & Display
33
 *
34
 * @igxTheme igx-button-theme
35
 *
36
 * @igxKeywords button, span, div, click
37
 *
38
 * @remarks
39
 * The Ignite UI Button directive is intended to be used by any button, span or div and turn it into a fully functional button.
40
 *
41
 * @example
42
 * ```html
43
 * <button type="button" igxButton="outlined">A Button</button>
44
 * ```
45
 */
46
@Directive({
47
    selector: '[igxButton]',
48
    standalone: true
49
})
50
export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterContentInit, OnDestroy {
2✔
51
    private static ngAcceptInputType_type: IgxButtonType | '';
52

53
    /**
54
     * Called when the button is selected.
55
     */
56
    @Output()
57
    public buttonSelected = new EventEmitter<IButtonEventArgs>();
422✔
58

59
    /**
60
     * @hidden
61
     * @internal
62
     */
63
    @HostBinding('class.igx-button')
64
    public _cssClass = 'igx-button';
422✔
65

66
    /**
67
     * @hidden
68
     * @internal
69
     */
70
    private _type: IgxButtonType;
71

72
    /**
73
     * @hidden
74
     * @internal
75
     */
76
    private _color: string;
77

78
    /**
79
     * @hidden
80
     * @internal
81
     */
82
    private _label: string;
83

84
    /**
85
     * @hidden
86
     * @internal
87
     */
88
    private _backgroundColor: string;
89

90
    /**
91
     * @hidden
92
     * @internal
93
     */
94
    private _selected = false;
422✔
95

96
    private emitSelected() {
97
        this.buttonSelected.emit({
50✔
98
            button: this
99
        });
100
    }
101

102
    /**
103
     * Gets or sets whether the button is selected.
104
     * Mainly used in the IgxButtonGroup component and it will have no effect if set separately.
105
     *
106
     * @example
107
     * ```html
108
     * <button type="button" igxButton="flat" [selected]="button.selected"></button>
109
     * ```
110
     */
111
    @Input({ transform: booleanAttribute })
112
    public set selected(value: boolean) {
UNCOV
113
        if (this._selected !== value) {
×
UNCOV
114
            this._selected = value;
×
UNCOV
115
            this._renderer.setAttribute(this.nativeElement, 'data-selected', value.toString());
×
116
        }
117
    }
118

119
    public get selected(): boolean {
UNCOV
120
        return this._selected;
×
121
    }
122

123
    constructor(
124
        public override element: ElementRef,
422✔
125
        private _renderer: Renderer2,
422✔
126
    ) {
127
        super(element);
422✔
128
    }
129

130
    public ngAfterContentInit() {
131
        this.nativeElement.addEventListener('click', this.emitSelected.bind(this));
422✔
132
    }
133

134
    public ngOnDestroy(): void {
135
        this.nativeElement.removeEventListener('click', this.emitSelected);
405✔
136
    }
137

138
    /**
139
     * Sets the type of the button.
140
     *
141
     * @example
142
     * ```html
143
     * <button type="button" igxButton="outlined"></button>
144
     * ```
145
     */
146
    @Input('igxButton')
147
    public set type(type: IgxButtonType) {
148
        const t = type ? type : IgxButtonType.Flat;
422✔
149
        if (this._type !== t) {
422✔
150
            this._type = t;
422✔
151
        }
152
    }
153

154
    /**
155
     * Sets the `aria-label` attribute.
156
     *
157
     * @example
158
     *  ```html
159
     * <button type="button" igxButton="flat" igxLabel="Label"></button>
160
     * ```
161
     */
162
    @Input('igxLabel')
163
    public set label(value: string) {
UNCOV
164
        this._label = value || this._label;
×
UNCOV
165
        this._renderer.setAttribute(this.nativeElement, 'aria-label', this._label);
×
166
    }
167

168
    /**
169
     * @hidden
170
     * @internal
171
     */
172
    @HostBinding('class.igx-button--flat')
173
    public get flat(): boolean {
174
        return this._type === IgxButtonType.Flat;
4,586✔
175
    }
176

177
    /**
178
     * @hidden
179
     * @internal
180
     */
181
    @HostBinding('class.igx-button--contained')
182
    public get contained(): boolean {
183
        return this._type === IgxButtonType.Contained;
4,586✔
184
    }
185

186
    /**
187
     * @hidden
188
     * @internal
189
     */
190
    @HostBinding('class.igx-button--outlined')
191
    public get outlined(): boolean {
192
        return this._type === IgxButtonType.Outlined;
4,586✔
193
    }
194

195
    /**
196
     * @hidden
197
     * @internal
198
     */
199
    @HostBinding('class.igx-button--fab')
200
    public get fab(): boolean {
201
        return this._type === IgxButtonType.FAB;
4,586✔
202
    }
203

204
    /**
205
     * @hidden
206
     * @internal
207
     */
208
    public select() {
UNCOV
209
        this.selected = true;
×
210
    }
211

212
    /**
213
     * @hidden
214
     * @internal
215
     */
216
    public deselect() {
UNCOV
217
        this.selected = false;
×
UNCOV
218
        this.focused = false;
×
219
    }
220
}
221

222
export interface IButtonEventArgs extends IBaseEventArgs {
223
    button: IgxButtonDirective;
224
}
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