File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed
projects/coreui-angular/src/lib/form/form-label Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change 1
1
import { FormLabelDirective } from './form-label.directive' ;
2
+ import { TestBed } from '@angular/core/testing' ;
2
3
3
4
describe ( 'LabelDirective' , ( ) => {
4
5
it ( 'should create an instance' , ( ) => {
5
- const directive = new FormLabelDirective ( ) ;
6
- expect ( directive ) . toBeTruthy ( ) ;
6
+ TestBed . runInInjectionContext ( ( ) => {
7
+ const directive = new FormLabelDirective ( ) ;
8
+ expect ( directive ) . toBeTruthy ( ) ;
9
+ } ) ;
7
10
} ) ;
8
11
} ) ;
Original file line number Diff line number Diff line change 1
- import { Directive , HostBinding , Input } from '@angular/core' ;
1
+ import { computed , Directive , input } from '@angular/core' ;
2
2
3
3
@Directive ( {
4
4
selector : '[cLabel]' ,
5
- host : { class : 'form-label' }
5
+ host : { class : 'form-label' , '[class]' : 'hostClasses()' }
6
6
} )
7
7
export class FormLabelDirective {
8
8
/**
9
9
* For horizontal forms set labels to 'col' and make them vertically centered with their associated form controls.
10
- * @type 'col '
10
+ * @default ' '
11
11
*/
12
- @ Input ( 'cLabel' ) col : 'col' | '' = '' ;
12
+ readonly col = input < 'col' | '' > ( '' , { alias : 'cLabel' } ) ;
13
13
/**
14
14
* Size the label small or large.
15
+ * @default ''
15
16
*/
16
- @ Input ( ) sizing : '' | 'sm' | 'lg' | string = '' ;
17
+ readonly sizing = input < '' | 'sm' | 'lg' | string > ( ) ;
17
18
18
- @HostBinding ( 'class' )
19
- get hostClasses ( ) : any {
19
+ readonly hostClasses = computed ( ( ) => {
20
+ const col = this . col ( ) ;
21
+ const sizing = this . sizing ( ) ;
20
22
return {
21
23
'form-label' : true ,
22
- 'col-form-label' : this . col === 'col' ,
23
- [ `col-form-label-${ this . sizing } ` ] : ! ! this . sizing && this . col === 'col'
24
- } ;
25
- }
24
+ 'col-form-label' : col === 'col' ,
25
+ [ `col-form-label-${ sizing } ` ] : ! ! sizing && col === 'col'
26
+ } as Record < string , boolean > ;
27
+ } ) ;
26
28
}
You can’t perform that action at this time.
0 commit comments