Skip to content

Commit f732451

Browse files
committed
refactor(form-floating): signal inputs, host bindings, cleanup
1 parent 452a96b commit f732451

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { TestBed } from '@angular/core/testing';
12
import { FormFloatingDirective } from './form-floating.directive';
23

34
describe('FormFloatingDirective', () => {
45
it('should create an instance', () => {
5-
const directive = new FormFloatingDirective();
6-
expect(directive).toBeTruthy();
6+
TestBed.runInInjectionContext(() => {
7+
const directive = new FormFloatingDirective();
8+
expect(directive).toBeTruthy();
9+
});
710
});
811
});
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { booleanAttribute, Directive, HostBinding, Input } from '@angular/core';
1+
import { booleanAttribute, computed, Directive, input } from '@angular/core';
22

33
@Directive({
4-
selector: '[cFormFloating]'
4+
selector: '[cFormFloating]',
5+
host: { '[class]': 'hostClasses()' }
56
})
67
export class FormFloatingDirective {
78
/**
89
* Enable floating labels
910
* @type boolean
1011
*/
11-
@Input({ alias: 'cFormFloating', transform: booleanAttribute }) floating: string | boolean = true;
12+
readonly floating = input(true, { transform: booleanAttribute, alias: 'cFormFloating' });
1213

13-
@HostBinding('class')
14-
get hostClasses(): any {
14+
readonly hostClasses = computed(() => {
1515
return {
16-
'form-floating': this.floating
16+
'form-floating': this.floating()
1717
};
18-
}
18+
});
1919
}

0 commit comments

Comments
 (0)