Skip to content

Commit 1589778

Browse files
authored
Revert "feat(checkbox): add options defaults config (#17473)"
This reverts commit 3fdab10.
1 parent 044a360 commit 1589778

File tree

5 files changed

+10
-152
lines changed

5 files changed

+10
-152
lines changed

src/material/checkbox/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ ng_test_library(
6161
":checkbox",
6262
"//src/cdk/observers",
6363
"//src/cdk/testing/private",
64-
"//src/material/core",
6564
"@npm//@angular/forms",
6665
"@npm//@angular/platform-browser",
6766
],

src/material/checkbox/checkbox-config.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {InjectionToken} from '@angular/core';
9-
import {ThemePalette} from '@angular/material/core';
109

11-
/** Default `mat-checkbox` options that can be overridden. */
12-
export interface MatCheckboxDefaultOptions {
13-
color?: ThemePalette;
14-
clickAction?: MatCheckboxClickAction;
15-
}
16-
17-
/** Injection token to be used to override the default options for `mat-checkbox`. */
18-
export const MAT_CHECKBOX_DEFAULT_OPTIONS =
19-
new InjectionToken<MatCheckboxDefaultOptions>('mat-checkbox-default-options', {
20-
providedIn: 'root',
21-
factory: MAT_CHECKBOX_DEFAULT_OPTIONS_FACTORY
22-
});
23-
24-
/** @docs-private */
25-
export function MAT_CHECKBOX_DEFAULT_OPTIONS_FACTORY(): MatCheckboxDefaultOptions {
26-
return {
27-
color: 'accent',
28-
clickAction: 'check-indeterminate',
29-
};
30-
}
3110

3211
/**
3312
* Checkbox click action when user click on input element.
@@ -40,8 +19,6 @@ export type MatCheckboxClickAction = 'noop' | 'check' | 'check-indeterminate' |
4019

4120
/**
4221
* Injection token that can be used to specify the checkbox click behavior.
43-
* @deprecated Injection token will be removed, use `MAT_CHECKBOX_DEFAULT_OPTIONS` instead.
44-
* @breaking-change 10.0.0
4522
*/
4623
export const MAT_CHECKBOX_CLICK_ACTION =
4724
new InjectionToken<MatCheckboxClickAction>('mat-checkbox-click-action');

src/material/checkbox/checkbox.spec.ts

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ import {FormControl, FormsModule, NgModel, ReactiveFormsModule} from '@angular/f
99
import {Component, DebugElement, ViewChild, Type, ChangeDetectionStrategy} from '@angular/core';
1010
import {By} from '@angular/platform-browser';
1111
import {dispatchFakeEvent} from '@angular/cdk/testing/private';
12-
import {
13-
MAT_CHECKBOX_DEFAULT_OPTIONS,
14-
MatCheckbox,
15-
MatCheckboxChange,
16-
MatCheckboxModule
17-
} from './index';
12+
import {MatCheckbox, MatCheckboxChange, MatCheckboxModule} from './index';
1813
import {MAT_CHECKBOX_CLICK_ACTION} from './checkbox-config';
1914
import {MutationObserverFactory} from '@angular/cdk/observers';
20-
import {ThemePalette} from '@angular/material/core';
2115

2216

2317
describe('MatCheckbox', () => {
@@ -539,47 +533,14 @@ describe('MatCheckbox', () => {
539533
}));
540534
});
541535

542-
describe(`when MAT_CHECKBOX_CLICK_ACTION is set`, () => {
543-
beforeEach(() => {
544-
TestBed.resetTestingModule();
545-
TestBed.configureTestingModule({
546-
imports: [MatCheckboxModule, FormsModule, ReactiveFormsModule],
547-
declarations: [SingleCheckbox],
548-
providers: [
549-
{provide: MAT_CHECKBOX_CLICK_ACTION, useValue: 'check'},
550-
{provide: MAT_CHECKBOX_DEFAULT_OPTIONS, useValue: {clickAction: 'noop'}}
551-
]
552-
});
553-
554-
fixture = createComponent(SingleCheckbox);
555-
fixture.detectChanges();
556-
557-
checkboxDebugElement = fixture.debugElement.query(By.directive(MatCheckbox))!;
558-
checkboxNativeElement = checkboxDebugElement.nativeElement;
559-
testComponent = fixture.debugElement.componentInstance;
560-
561-
inputElement = checkboxNativeElement.querySelector('input') as HTMLInputElement;
562-
});
563-
564-
it('should override the value set in the default options', fakeAsync(() => {
565-
testComponent.isIndeterminate = true;
566-
inputElement.click();
567-
fixture.detectChanges();
568-
flush();
569-
570-
expect(inputElement.checked).toBe(true);
571-
expect(inputElement.indeterminate).toBe(true);
572-
}));
573-
});
574-
575536
describe(`when MAT_CHECKBOX_CLICK_ACTION is 'check'`, () => {
576537
beforeEach(() => {
577538
TestBed.resetTestingModule();
578539
TestBed.configureTestingModule({
579540
imports: [MatCheckboxModule, FormsModule, ReactiveFormsModule],
580541
declarations: [SingleCheckbox],
581542
providers: [
582-
{provide: MAT_CHECKBOX_DEFAULT_OPTIONS, useValue: {clickAction: 'check'}}
543+
{provide: MAT_CHECKBOX_CLICK_ACTION, useValue: 'check'}
583544
]
584545
});
585546

@@ -616,7 +577,7 @@ describe('MatCheckbox', () => {
616577
imports: [MatCheckboxModule, FormsModule, ReactiveFormsModule],
617578
declarations: [SingleCheckbox],
618579
providers: [
619-
{provide: MAT_CHECKBOX_DEFAULT_OPTIONS, useValue: {clickAction: 'noop'}}
580+
{provide: MAT_CHECKBOX_CLICK_ACTION, useValue: 'noop'}
620581
]
621582
});
622583

@@ -1194,50 +1155,6 @@ describe('MatCheckbox', () => {
11941155
});
11951156
});
11961157

1197-
describe('MatCheckboxDefaultOptions', () => {
1198-
describe('when MAT_CHECKBOX_DEFAULT_OPTIONS overridden', () => {
1199-
beforeEach(() => {
1200-
TestBed.configureTestingModule({
1201-
imports: [MatCheckboxModule, FormsModule],
1202-
declarations: [SingleCheckbox, SimpleCheckbox],
1203-
providers: [{
1204-
provide: MAT_CHECKBOX_DEFAULT_OPTIONS,
1205-
useValue: {color: 'primary'},
1206-
}],
1207-
});
1208-
1209-
TestBed.compileComponents();
1210-
});
1211-
1212-
it('should override default color in Component', () => {
1213-
const fixture: ComponentFixture<SimpleCheckbox> =
1214-
TestBed.createComponent(SimpleCheckbox);
1215-
fixture.detectChanges();
1216-
const checkboxDebugElement: DebugElement =
1217-
fixture.debugElement.query(By.directive(MatCheckbox))!;
1218-
expect(
1219-
checkboxDebugElement.nativeElement.classList
1220-
).toContain('mat-primary');
1221-
});
1222-
1223-
it('should not override explicit input bindings', () => {
1224-
const fixture: ComponentFixture<SingleCheckbox> =
1225-
TestBed.createComponent(SingleCheckbox);
1226-
fixture.componentInstance.checkboxColor = 'warn';
1227-
fixture.detectChanges();
1228-
const checkboxDebugElement: DebugElement =
1229-
fixture.debugElement.query(By.directive(MatCheckbox))!;
1230-
expect(
1231-
checkboxDebugElement.nativeElement.classList
1232-
).not.toContain('mat-primary');
1233-
expect(
1234-
checkboxDebugElement.nativeElement.classList
1235-
).toContain('mat-warn');
1236-
expect(checkboxDebugElement.nativeElement.classList).toContain('mat-warn');
1237-
});
1238-
});
1239-
});
1240-
12411158
/** Simple component for testing a single checkbox. */
12421159
@Component({
12431160
template: `
@@ -1268,7 +1185,7 @@ class SingleCheckbox {
12681185
parentElementClicked: boolean = false;
12691186
parentElementKeyedUp: boolean = false;
12701187
checkboxId: string | null = 'simple-check';
1271-
checkboxColor: ThemePalette = 'primary';
1188+
checkboxColor: string = 'primary';
12721189
checkboxValue: string = 'single_checkbox';
12731190

12741191
onCheckboxClick: (event?: Event) => void = () => {};
@@ -1389,8 +1306,3 @@ class CheckboxWithProjectedLabel {}
13891306
class TextBindingComponent {
13901307
text: string = 'Some text';
13911308
}
1392-
1393-
/** Test component with a simple checkbox with no inputs. */
1394-
@Component({template: `<mat-checkbox></mat-checkbox>`})
1395-
class SimpleCheckbox {
1396-
}

src/material/checkbox/checkbox.ts

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

9-
import {FocusableOption, FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
9+
import {FocusMonitor, FocusableOption, FocusOrigin} from '@angular/cdk/a11y';
1010
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {
12-
AfterViewChecked,
1312
Attribute,
1413
ChangeDetectionStrategy,
1514
ChangeDetectorRef,
@@ -25,6 +24,7 @@ import {
2524
Output,
2625
ViewChild,
2726
ViewEncapsulation,
27+
AfterViewChecked,
2828
} from '@angular/core';
2929
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
3030
import {
@@ -43,12 +43,7 @@ import {
4343
mixinTabIndex,
4444
} from '@angular/material/core';
4545
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
46-
import {
47-
MAT_CHECKBOX_CLICK_ACTION,
48-
MAT_CHECKBOX_DEFAULT_OPTIONS,
49-
MatCheckboxClickAction,
50-
MatCheckboxDefaultOptions
51-
} from './checkbox-config';
46+
import {MAT_CHECKBOX_CLICK_ACTION, MatCheckboxClickAction} from './checkbox-config';
5247

5348

5449
// Increasing integer for generating unique ids for checkbox components.
@@ -99,7 +94,7 @@ const _MatCheckboxMixinBase:
9994
CanDisableRippleCtor &
10095
CanDisableCtor &
10196
typeof MatCheckboxBase =
102-
mixinTabIndex(mixinColor(mixinDisableRipple(mixinDisabled(MatCheckboxBase))));
97+
mixinTabIndex(mixinColor(mixinDisableRipple(mixinDisabled(MatCheckboxBase)), 'accent'));
10398

10499

105100
/**
@@ -199,22 +194,10 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
199194
private _focusMonitor: FocusMonitor,
200195
private _ngZone: NgZone,
201196
@Attribute('tabindex') tabIndex: string,
202-
/**
203-
* @deprecated `_clickAction` parameter to be removed, use
204-
* `MAT_CHECKBOX_DEFAULT_OPTIONS`
205-
* @breaking-change 10.0.0
206-
*/
207197
@Optional() @Inject(MAT_CHECKBOX_CLICK_ACTION)
208198
private _clickAction: MatCheckboxClickAction,
209-
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
210-
@Optional() @Inject(MAT_CHECKBOX_DEFAULT_OPTIONS)
211-
private _options?: MatCheckboxDefaultOptions) {
199+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
212200
super(elementRef);
213-
this._options = this._options || {};
214-
215-
if (this._options.color) {
216-
this.color = this._options.color;
217-
}
218201

219202
this.tabIndex = parseInt(tabIndex) || 0;
220203

@@ -231,9 +214,6 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
231214
});
232215
}
233216
});
234-
235-
// TODO: Remove this after the `_clickAction` parameter is removed as an injection parameter.
236-
this._clickAction = this._clickAction || this._options.clickAction;
237217
}
238218

239219
// TODO: Delete next major revision.

tools/public_api_guard/material/checkbox.d.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ export declare const MAT_CHECKBOX_CLICK_ACTION: InjectionToken<MatCheckboxClickA
55

66
export declare const MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR: any;
77

8-
export declare const MAT_CHECKBOX_DEFAULT_OPTIONS: InjectionToken<MatCheckboxDefaultOptions>;
9-
10-
export declare function MAT_CHECKBOX_DEFAULT_OPTIONS_FACTORY(): MatCheckboxDefaultOptions;
11-
128
export declare const MAT_CHECKBOX_REQUIRED_VALIDATOR: Provider;
139

1410
export declare class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAccessor, AfterViewChecked, OnDestroy, CanColor, CanDisable, HasTabIndex, CanDisableRipple, FocusableOption {
@@ -29,8 +25,7 @@ export declare class MatCheckbox extends _MatCheckboxMixinBase implements Contro
2925
required: boolean;
3026
ripple: MatRipple;
3127
value: string;
32-
constructor(elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, _focusMonitor: FocusMonitor, _ngZone: NgZone, tabIndex: string,
33-
_clickAction: MatCheckboxClickAction, _animationMode?: string | undefined, _options?: MatCheckboxDefaultOptions | undefined);
28+
constructor(elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, _focusMonitor: FocusMonitor, _ngZone: NgZone, tabIndex: string, _clickAction: MatCheckboxClickAction, _animationMode?: string | undefined);
3429
_getAriaChecked(): 'true' | 'false' | 'mixed';
3530
_isRippleDisabled(): any;
3631
_onInputClick(event: Event): void;
@@ -53,11 +48,6 @@ export declare class MatCheckboxChange {
5348

5449
export declare type MatCheckboxClickAction = 'noop' | 'check' | 'check-indeterminate' | undefined;
5550

56-
export interface MatCheckboxDefaultOptions {
57-
clickAction?: MatCheckboxClickAction;
58-
color?: ThemePalette;
59-
}
60-
6151
export declare class MatCheckboxModule {
6252
}
6353

0 commit comments

Comments
 (0)