Skip to content

Commit 4b0a603

Browse files
committed
refactor(material/core): remove mixin class usages
Replaces mixin class usages in the option and option group with input transforms.
1 parent f2dcb65 commit 4b0a603

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/material/core/option/optgroup.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
Inject,
1515
Optional,
1616
InjectionToken,
17+
booleanAttribute,
1718
} from '@angular/core';
18-
import {CanDisable, mixinDisabled} from '../common-behaviors/disabled';
1919
import {MatOptionParentComponent, MAT_OPTION_PARENT_COMPONENT} from './option-parent';
2020

2121
// Notes on the accessibility pattern used for `mat-optgroup`.
@@ -38,10 +38,6 @@ import {MatOptionParentComponent, MAT_OPTION_PARENT_COMPONENT} from './option-pa
3838
// 3. `<mat-option aria-labelledby="optionLabel groupLabel"` - This works on Chrome, but Safari
3939
// doesn't read out the text at all. Furthermore, on
4040

41-
// Boilerplate for applying mixins to MatOptgroup.
42-
/** @docs-private */
43-
const _MatOptgroupMixinBase = mixinDisabled(class {});
44-
4541
// Counter for unique group ids.
4642
let _uniqueOptgroupIdCounter = 0;
4743

@@ -61,7 +57,6 @@ export const MAT_OPTGROUP = new InjectionToken<MatOptgroup>('MatOptgroup');
6157
templateUrl: 'optgroup.html',
6258
encapsulation: ViewEncapsulation.None,
6359
changeDetection: ChangeDetectionStrategy.OnPush,
64-
inputs: ['disabled'],
6560
styleUrls: ['optgroup.css'],
6661
host: {
6762
'class': 'mat-mdc-optgroup',
@@ -71,18 +66,20 @@ export const MAT_OPTGROUP = new InjectionToken<MatOptgroup>('MatOptgroup');
7166
},
7267
providers: [{provide: MAT_OPTGROUP, useExisting: MatOptgroup}],
7368
})
74-
export class MatOptgroup extends _MatOptgroupMixinBase implements CanDisable {
69+
export class MatOptgroup {
7570
/** Label for the option group. */
7671
@Input() label: string;
7772

73+
/** whether the option group is disabled. */
74+
@Input({transform: booleanAttribute}) disabled: boolean = false;
75+
7876
/** Unique id for the underlying label. */
7977
_labelId: string = `mat-optgroup-label-${_uniqueOptgroupIdCounter++}`;
8078

8179
/** Whether the group is in inert a11y mode. */
8280
_inert: boolean;
8381

8482
constructor(@Inject(MAT_OPTION_PARENT_COMPONENT) @Optional() parent?: MatOptionParentComponent) {
85-
super();
8683
this._inert = parent?.inertGroups ?? false;
8784
}
8885
}

src/material/core/option/option.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {FocusableOption, FocusOrigin} from '@angular/cdk/a11y';
10-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1110
import {ENTER, hasModifierKey, SPACE} from '@angular/cdk/keycodes';
1211
import {
1312
Component,
@@ -24,6 +23,7 @@ import {
2423
EventEmitter,
2524
QueryList,
2625
ViewChild,
26+
booleanAttribute,
2727
} from '@angular/core';
2828
import {Subject} from 'rxjs';
2929
import {MAT_OPTGROUP, MatOptgroup} from './optgroup';
@@ -101,12 +101,12 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
101101
@Input() id: string = `mat-option-${_uniqueIdCounter++}`;
102102

103103
/** Whether the option is disabled. */
104-
@Input()
104+
@Input({transform: booleanAttribute})
105105
get disabled(): boolean {
106106
return (this.group && this.group.disabled) || this._disabled;
107107
}
108-
set disabled(value: BooleanInput) {
109-
this._disabled = coerceBooleanProperty(value);
108+
set disabled(value: boolean) {
109+
this._disabled = value;
110110
}
111111

112112
/** Whether ripples for the option are disabled. */

tools/public_api_guard/material/core.md

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

7-
import { _AbstractConstructor as _AbstractConstructor_2 } from '@angular/material/core';
87
import { AbstractControl } from '@angular/forms';
98
import { AfterViewChecked } from '@angular/core';
10-
import { BooleanInput } from '@angular/cdk/coercion';
119
import { ChangeDetectorRef } from '@angular/core';
12-
import { _Constructor as _Constructor_2 } from '@angular/material/core';
1310
import { ElementRef } from '@angular/core';
1411
import { EventEmitter } from '@angular/core';
1512
import { FocusableOption } from '@angular/cdk/a11y';
@@ -240,13 +237,16 @@ export class MatNativeDateModule {
240237
}
241238

242239
// @public
243-
export class MatOptgroup extends _MatOptgroupMixinBase implements CanDisable {
240+
export class MatOptgroup {
244241
constructor(parent?: MatOptionParentComponent);
242+
disabled: boolean;
245243
_inert: boolean;
246244
label: string;
247245
_labelId: string;
248246
// (undocumented)
249-
static ɵcmp: i0.ɵɵComponentDeclaration<MatOptgroup, "mat-optgroup", ["matOptgroup"], { "disabled": { "alias": "disabled"; "required": false; }; "label": { "alias": "label"; "required": false; }; }, {}, never, ["*", "mat-option, ng-container"], false, never>;
247+
static ngAcceptInputType_disabled: unknown;
248+
// (undocumented)
249+
static ɵcmp: i0.ɵɵComponentDeclaration<MatOptgroup, "mat-optgroup", ["matOptgroup"], { "label": { "alias": "label"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; }, {}, never, ["*", "mat-option, ng-container"], false, never>;
250250
// (undocumented)
251251
static ɵfac: i0.ɵɵFactoryDeclaration<MatOptgroup, [{ optional: true; }]>;
252252
}
@@ -259,7 +259,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
259259
_changeDetectorRef: ChangeDetectorRef;
260260
deselect(emitEvent?: boolean): void;
261261
get disabled(): boolean;
262-
set disabled(value: BooleanInput);
262+
set disabled(value: boolean);
263263
get disableRipple(): boolean;
264264
focus(_origin?: FocusOrigin, options?: FocusOptions): void;
265265
_getHostElement(): HTMLElement;
@@ -272,6 +272,8 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
272272
id: string;
273273
get multiple(): boolean | undefined;
274274
// (undocumented)
275+
static ngAcceptInputType_disabled: unknown;
276+
// (undocumented)
275277
ngAfterViewChecked(): void;
276278
// (undocumented)
277279
ngOnDestroy(): void;

0 commit comments

Comments
 (0)