Skip to content

Commit 791db87

Browse files
committed
refactor(form-select): signal inputs, host bindings, cleanup
1 parent 232112a commit 791db87

File tree

2 files changed

+18
-13
lines changed

2 files changed

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

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

33
@Directive({
44
selector: 'select[cSelect]',
5-
host: { class: 'form-select' }
5+
host: { class: 'form-select', '[class]': 'hostClasses()' }
66
})
77
export class FormSelectDirective {
88
/**
99
* Size the component small or large.
10+
* @default undefined
1011
*/
11-
@Input() sizing?: '' | 'sm' | 'lg' | string = '';
12+
readonly sizing = input<'' | 'sm' | 'lg' | string>();
1213

1314
/**
1415
* Set component validation state to valid.
15-
* @type {boolean | undefined}
16+
* @default undefined
1617
*/
17-
@Input() valid?: boolean;
18+
readonly valid = input<boolean>();
1819

19-
@HostBinding('class')
20-
get hostClasses(): any {
20+
readonly hostClasses = computed(() => {
21+
const sizing = this.sizing();
22+
const valid = this.valid();
2123
return {
2224
'form-select': true,
23-
[`form-select-${this.sizing}`]: !!this.sizing,
24-
'is-valid': this.valid === true,
25-
'is-invalid': this.valid === false
25+
[`form-select-${sizing}`]: !!sizing,
26+
'is-valid': valid === true,
27+
'is-invalid': valid === false
2628
};
27-
}
29+
});
2830
}

0 commit comments

Comments
 (0)