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 11import { FormLabelDirective } from './form-label.directive' ;
2+ import { TestBed } from '@angular/core/testing' ;
23
34describe ( 'LabelDirective' , ( ) => {
45 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+ } ) ;
710 } ) ;
811} ) ;
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' ;
22
33@Directive ( {
44 selector : '[cLabel]' ,
5- host : { class : 'form-label' }
5+ host : { class : 'form-label' , '[class]' : 'hostClasses()' }
66} )
77export class FormLabelDirective {
88 /**
99 * For horizontal forms set labels to 'col' and make them vertically centered with their associated form controls.
10- * @type 'col '
10+ * @default ' '
1111 */
12- @ Input ( 'cLabel' ) col : 'col' | '' = '' ;
12+ readonly col = input < 'col' | '' > ( '' , { alias : 'cLabel' } ) ;
1313 /**
1414 * Size the label small or large.
15+ * @default ''
1516 */
16- @ Input ( ) sizing : '' | 'sm' | 'lg' | string = '' ;
17+ readonly sizing = input < '' | 'sm' | 'lg' | string > ( ) ;
1718
18- @HostBinding ( 'class' )
19- get hostClasses ( ) : any {
19+ readonly hostClasses = computed ( ( ) => {
20+ const col = this . col ( ) ;
21+ const sizing = this . sizing ( ) ;
2022 return {
2123 '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+ } ) ;
2628}
You can’t perform that action at this time.
0 commit comments