Skip to content

Commit d462648

Browse files
committed
refactor(accordion): @input() transform instead of @angular/cdk coerce functions
1 parent f912d62 commit d462648

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
import { Component, HostBinding, Input } from '@angular/core';
2-
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
1+
import { booleanAttribute, Component, HostBinding, inject, Input } from '@angular/core';
32

43
import { AccordionService } from '../accordion.service';
54

65
@Component({
76
selector: 'c-accordion',
8-
template: `<ng-content></ng-content>`,
7+
template: '<ng-content/>',
98
styleUrls: ['./accordion.component.scss'],
109
exportAs: 'cAccordionItem',
1110
providers: [AccordionService],
1211
standalone: true
1312
})
1413
export class AccordionComponent {
1514

16-
static ngAcceptInputType_alwaysOpen: BooleanInput;
15+
#accordionService = inject(AccordionService);
1716

1817
/**
1918
* Removes the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container.
2019
* @type boolean
2120
*/
22-
@Input() flush?: boolean;
21+
@Input({ transform: booleanAttribute }) flush: boolean = false;
22+
2323
/**
2424
* Make accordion items stay open when another item is opened
2525
* @type boolean
2626
*/
27-
@Input()
27+
@Input({ transform: booleanAttribute })
2828
set alwaysOpen(value: boolean) {
29-
this.accordionService.alwaysOpen = coerceBooleanProperty(value);
29+
this.#accordionService.alwaysOpen = value;
3030
}
31+
3132
get alwaysOpen(): boolean {
32-
return this.accordionService.alwaysOpen;
33+
return this.#accordionService.alwaysOpen;
3334
}
3435

3536
@HostBinding('class')
3637
get hostClasses(): any {
3738
return {
3839
accordion: true,
39-
'accordion-flush': !!this.flush
40+
'accordion-flush': this.flush
4041
};
4142
}
4243

43-
constructor(
44-
private accordionService: AccordionService
45-
) {}
46-
4744
}

0 commit comments

Comments
 (0)