Skip to content

Commit e058009

Browse files
committed
refactor(cdk/accordion): switch to input transforms
Switches inputs in cdk/accordion to use transforms instead of getters/setters.
1 parent d2253b9 commit e058009

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

src/cdk/accordion/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ ng_module(
1515
exclude = ["**/*.spec.ts"],
1616
),
1717
deps = [
18-
"//src/cdk/coercion",
1918
"//src/cdk/collections",
2019
"@npm//@angular/core",
2120
"@npm//rxjs",

src/cdk/accordion/accordion-item.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
ChangeDetectorRef,
1717
SkipSelf,
1818
Inject,
19+
booleanAttribute,
1920
} from '@angular/core';
2021
import {UniqueSelectionDispatcher} from '@angular/cdk/collections';
2122
import {CDK_ACCORDION, CdkAccordion} from './accordion';
22-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
2323
import {Subscription} from 'rxjs';
2424

2525
/** Used to generate unique ID for each accordion item. */
@@ -59,13 +59,11 @@ export class CdkAccordionItem implements OnDestroy {
5959
readonly id: string = `cdk-accordion-child-${nextId++}`;
6060

6161
/** Whether the AccordionItem is expanded. */
62-
@Input()
62+
@Input({transform: booleanAttribute})
6363
get expanded(): boolean {
6464
return this._expanded;
6565
}
66-
set expanded(expanded: BooleanInput) {
67-
expanded = coerceBooleanProperty(expanded);
68-
66+
set expanded(expanded: boolean) {
6967
// Only emit events and update the internal value if the value changes.
7068
if (this._expanded !== expanded) {
7169
this._expanded = expanded;
@@ -91,14 +89,7 @@ export class CdkAccordionItem implements OnDestroy {
9189
private _expanded = false;
9290

9391
/** Whether the AccordionItem is disabled. */
94-
@Input()
95-
get disabled(): boolean {
96-
return this._disabled;
97-
}
98-
set disabled(disabled: BooleanInput) {
99-
this._disabled = coerceBooleanProperty(disabled);
100-
}
101-
private _disabled = false;
92+
@Input({transform: booleanAttribute}) disabled: boolean = false;
10293

10394
/** Unregister function for _expansionDispatcher. */
10495
private _removeUniqueSelectionListener: () => void = () => {};

src/cdk/accordion/accordion.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
10-
import {Directive, InjectionToken, Input, OnChanges, OnDestroy, SimpleChanges} from '@angular/core';
9+
import {
10+
Directive,
11+
InjectionToken,
12+
Input,
13+
OnChanges,
14+
OnDestroy,
15+
SimpleChanges,
16+
booleanAttribute,
17+
} from '@angular/core';
1118
import {Subject} from 'rxjs';
1219

1320
/** Used to generate unique ID for each accordion. */
@@ -39,18 +46,11 @@ export class CdkAccordion implements OnDestroy, OnChanges {
3946
readonly id: string = `cdk-accordion-${nextId++}`;
4047

4148
/** Whether the accordion should allow multiple expanded accordion items simultaneously. */
42-
@Input()
43-
get multi(): boolean {
44-
return this._multi;
45-
}
46-
set multi(multi: BooleanInput) {
47-
this._multi = coerceBooleanProperty(multi);
48-
}
49-
private _multi: boolean = false;
49+
@Input({transform: booleanAttribute}) multi: boolean = false;
5050

5151
/** Opens all enabled accordion items in an accordion where multi is enabled. */
5252
openAll(): void {
53-
if (this._multi) {
53+
if (this.multi) {
5454
this._openCloseAllActions.next(true);
5555
}
5656
}

tools/public_api_guard/cdk/accordion.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
```ts
66

7-
import { BooleanInput } from '@angular/cdk/coercion';
87
import { ChangeDetectorRef } from '@angular/core';
98
import { EventEmitter } from '@angular/core';
109
import * as i0 from '@angular/core';
@@ -19,8 +18,9 @@ import { UniqueSelectionDispatcher } from '@angular/cdk/collections';
1918
export class CdkAccordion implements OnDestroy, OnChanges {
2019
closeAll(): void;
2120
readonly id: string;
22-
get multi(): boolean;
23-
set multi(multi: BooleanInput);
21+
multi: boolean;
22+
// (undocumented)
23+
static ngAcceptInputType_multi: unknown;
2424
// (undocumented)
2525
ngOnChanges(changes: SimpleChanges): void;
2626
// (undocumented)
@@ -42,14 +42,17 @@ export class CdkAccordionItem implements OnDestroy {
4242
close(): void;
4343
readonly closed: EventEmitter<void>;
4444
readonly destroyed: EventEmitter<void>;
45-
get disabled(): boolean;
46-
set disabled(disabled: BooleanInput);
45+
disabled: boolean;
4746
get expanded(): boolean;
48-
set expanded(expanded: BooleanInput);
47+
set expanded(expanded: boolean);
4948
readonly expandedChange: EventEmitter<boolean>;
5049
// (undocumented)
5150
protected _expansionDispatcher: UniqueSelectionDispatcher;
5251
readonly id: string;
52+
// (undocumented)
53+
static ngAcceptInputType_disabled: unknown;
54+
// (undocumented)
55+
static ngAcceptInputType_expanded: unknown;
5356
ngOnDestroy(): void;
5457
open(): void;
5558
readonly opened: EventEmitter<void>;

0 commit comments

Comments
 (0)