Content-Length: 508377 | pFad | https://github.com/angular/components/commit/d120f973f8bc1f665a1d7bda9b6bacc92b4c18fb

AF fix(material/list): resolve changed after checked error · angular/components@d120f97 · GitHub
Skip to content

Commit d120f97

Browse files
committed
fix(material/list): resolve changed after checked error
Resolves a "changed after checked" error in the list due to the disabled state of the item being dependent on the state of the list. (cherry picked from commit 83f9123)
1 parent ab0d1c3 commit d120f97

File tree

3 files changed

+12
-43
lines changed

3 files changed

+12
-43
lines changed

src/material/list/list-base.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
OnDestroy,
2020
QueryList,
2121
Injector,
22+
signal,
2223
} from '@angular/core';
2324
import {
2425
_animationsDisabled,
@@ -64,12 +65,12 @@ export abstract class MatListBase {
6465
*/
6566
@Input()
6667
get disabled(): boolean {
67-
return this._disabled;
68+
return this._disabled();
6869
}
6970
set disabled(value: BooleanInput) {
70-
this._disabled = coerceBooleanProperty(value);
71+
this._disabled.set(coerceBooleanProperty(value));
7172
}
72-
private _disabled = false;
73+
private _disabled = signal(false);
7374

7475
protected _defaultOptions = inject(MAT_LIST_CONFIG, {optional: true});
7576
}
@@ -149,12 +150,12 @@ export abstract class MatListItemBase implements AfterViewInit, OnDestroy, Rippl
149150
/** Whether the list-item is disabled. */
150151
@Input()
151152
get disabled(): boolean {
152-
return this._disabled || !!this._listBase?.disabled;
153+
return this._disabled() || !!this._listBase?.disabled;
153154
}
154155
set disabled(value: BooleanInput) {
155-
this._disabled = coerceBooleanProperty(value);
156+
this._disabled.set(coerceBooleanProperty(value));
156157
}
157-
private _disabled = false;
158+
private _disabled = signal(false);
158159

159160
private _subscriptions = new Subscription();
160161
private _rippleRenderer: RippleRenderer | null = null;

src/material/list/selection-list.spec.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ChangeDetectionStrategy,
1111
Component,
1212
DebugElement,
13-
provideCheckNoChangesConfig,
1413
QueryList,
1514
ViewChildren,
1615
} from '@angular/core';
@@ -43,21 +42,6 @@ describe('MatSelectionList without forms', () => {
4342
let listOptions: DebugElement[];
4443
let selectionList: DebugElement;
4544

46-
beforeEach(waitForAsync(() => {
47-
TestBed.configureTestingModule({
48-
providers: [provideCheckNoChangesConfig({exhaustive: false})],
49-
imports: [
50-
MatListModule,
51-
SelectionListWithListOptions,
52-
SelectionListWithCheckboxPositionAfter,
53-
SelectionListWithListDisabled,
54-
SelectionListWithOnlyOneOption,
55-
SelectionListWithIndirectChildOptions,
56-
SelectionListWithSelectedOptionAndValue,
57-
],
58-
});
59-
}));
60-
6145
beforeEach(waitForAsync(() => {
6246
fixture = TestBed.createComponent(SelectionListWithListOptions);
6347
fixture.detectChanges();
@@ -1277,23 +1261,6 @@ describe('MatSelectionList without forms', () => {
12771261
});
12781262

12791263
describe('MatSelectionList with forms', () => {
1280-
beforeEach(waitForAsync(() => {
1281-
TestBed.configureTestingModule({
1282-
providers: [provideCheckNoChangesConfig({exhaustive: false})],
1283-
imports: [
1284-
MatListModule,
1285-
FormsModule,
1286-
ReactiveFormsModule,
1287-
SelectionListWithModel,
1288-
SelectionListWithFormControl,
1289-
SelectionListWithPreselectedOption,
1290-
SelectionListWithPreselectedOptionAndModel,
1291-
SelectionListWithPreselectedFormControlOnPush,
1292-
SelectionListWithCustomComparator,
1293-
],
1294-
});
1295-
}));
1296-
12971264
describe('and ngModel', () => {
12981265
let fixture: ComponentFixture<SelectionListWithModel>;
12991266
let selectionListDebug: DebugElement;

src/material/list/selection-list.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
ViewEncapsulation,
3131
forwardRef,
3232
inject,
33+
signal,
3334
} from '@angular/core';
3435
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
3536
import {ThemePalette} from '../core';
@@ -265,18 +266,18 @@ export class MatSelectionList
265266
*/
266267
@Input()
267268
override get disabled(): boolean {
268-
return this._selectionListDisabled;
269+
return this._selectionListDisabled();
269270
}
270271
override set disabled(value: BooleanInput) {
271272
// Update the disabled state of this list. Write to `this._selectionListDisabled` instead of
272273
// `super.disabled`. That is to avoid closure compiler compatibility issues with assigning to
273274
// a super property.
274-
this._selectionListDisabled = coerceBooleanProperty(value);
275-
if (this._selectionListDisabled) {
275+
this._selectionListDisabled.set(coerceBooleanProperty(value));
276+
if (this._selectionListDisabled()) {
276277
this._keyManager?.setActiveItem(-1);
277278
}
278279
}
279-
private _selectionListDisabled = false;
280+
private _selectionListDisabled = signal(false);
280281

281282
/** Implemented as part of ControlValueAccessor. */
282283
registerOnChange(fn: (value: any) => void): void {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/components/commit/d120f973f8bc1f665a1d7bda9b6bacc92b4c18fb

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy