Skip to content

Commit 23ab901

Browse files
ColinFrickMarkColeman1
authored andcommitted
refactor: migrate to input signals
1 parent 28a7470 commit 23ab901

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { booleanAttribute, Directive, ElementRef, inject, Input } from '@angular/core';
1+
import { booleanAttribute, Directive, effect, ElementRef, inject, input } from '@angular/core';
22

33
/**
44
* Row Disable Directive
@@ -15,26 +15,27 @@ import { booleanAttribute, Directive, ElementRef, inject, Input } from '@angular
1515
selector: '[disable-row]'
1616
})
1717
export class DisableRowDirective {
18-
private element = inject(ElementRef);
19-
private _disabled = false;
20-
@Input({ transform: booleanAttribute }) set disabled(val: boolean) {
21-
this._disabled = val;
22-
if (val) {
23-
this.disableAllElements();
24-
}
25-
}
18+
private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
2619

27-
get disabled() {
28-
return this._disabled;
20+
readonly disabled = input(false, {
21+
transform: booleanAttribute
22+
});
23+
24+
constructor() {
25+
effect(() => {
26+
if (this.disabled()) {
27+
this.disableAllElements();
28+
}
29+
});
2930
}
3031

31-
disableAllElements() {
32-
const el = this.element?.nativeElement;
33-
if (!el) {
32+
private disableAllElements() {
33+
const hostElement = this.elementRef?.nativeElement;
34+
if (!hostElement) {
3435
return;
3536
}
36-
Array.from(el.querySelectorAll('*') as HTMLAllCollection).forEach(child => {
37-
child?.setAttribute('disabled', '');
37+
Array.from(hostElement.querySelectorAll<HTMLElement>('*')).forEach(child => {
38+
child.setAttribute('disabled', '');
3839
});
3940
}
4041
}

0 commit comments

Comments
 (0)