Skip to content

Commit 77c8534

Browse files
committed
fix(cdk/accordion): resolve changed after checked error
Fixes a "changed after checked" error in the expansion panel due to the header depending on the `disabled` value of the expansion panel. (cherry picked from commit 0612c6a)
1 parent 325b017 commit 77c8534

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

goldens/cdk/accordion/index.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export class CdkAccordionItem implements OnInit, OnDestroy {
4444
close(): void;
4545
readonly closed: EventEmitter<void>;
4646
readonly destroyed: EventEmitter<void>;
47-
disabled: boolean;
47+
get disabled(): boolean;
48+
set disabled(value: boolean);
4849
get expanded(): boolean;
4950
set expanded(expanded: boolean);
5051
readonly expandedChange: EventEmitter<boolean>;

src/cdk/accordion/accordion-item.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
booleanAttribute,
1717
inject,
1818
OnInit,
19+
signal,
1920
} from '@angular/core';
2021
import {_IdGenerator} from '../a11y';
2122
import {UniqueSelectionDispatcher} from '../collections';
@@ -90,7 +91,14 @@ export class CdkAccordionItem implements OnInit, OnDestroy {
9091
private _expanded = false;
9192

9293
/** Whether the AccordionItem is disabled. */
93-
@Input({transform: booleanAttribute}) disabled: boolean = false;
94+
@Input({transform: booleanAttribute})
95+
get disabled() {
96+
return this._disabled();
97+
}
98+
set disabled(value: boolean) {
99+
this._disabled.set(value);
100+
}
101+
private _disabled = signal(false);
94102

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

src/material/expansion/accordion.spec.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import {
55
dispatchEvent,
66
dispatchKeyboardEvent,
77
} from '@angular/cdk/testing/private';
8-
import {
9-
Component,
10-
provideCheckNoChangesConfig,
11-
QueryList,
12-
ViewChild,
13-
ViewChildren,
14-
} from '@angular/core';
8+
import {Component, QueryList, ViewChild, ViewChildren} from '@angular/core';
159
import {TestBed, waitForAsync} from '@angular/core/testing';
1610
import {By} from '@angular/platform-browser';
1711
import {
@@ -25,18 +19,6 @@ describe('MatAccordion', () => {
2519
let focusMonitor: FocusMonitor;
2620

2721
beforeEach(waitForAsync(() => {
28-
TestBed.configureTestingModule({
29-
providers: [provideCheckNoChangesConfig({exhaustive: false})],
30-
imports: [
31-
MatExpansionModule,
32-
AccordionWithHideToggle,
33-
AccordionWithTogglePosition,
34-
NestedPanel,
35-
SetOfItems,
36-
NestedAccordions,
37-
],
38-
});
39-
4022
focusMonitor = TestBed.inject(FocusMonitor);
4123
}));
4224

0 commit comments

Comments
 (0)