-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material-experimental/mdc-checkbox): add default options #17578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrewseguin
merged 2 commits into
angular:master
from
andrewseguin:mdc-checkbox-options
Nov 4, 2019
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,11 @@ import { | |
| ViewEncapsulation | ||
| } from '@angular/core'; | ||
| import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; | ||
| import {MAT_CHECKBOX_CLICK_ACTION, MatCheckboxClickAction} from '@angular/material/checkbox'; | ||
| import { | ||
| MAT_CHECKBOX_CLICK_ACTION, | ||
| MAT_CHECKBOX_DEFAULT_OPTIONS, | ||
| MatCheckboxClickAction, MatCheckboxDefaultOptions | ||
| } from '@angular/material/checkbox'; | ||
| import {ThemePalette} from '@angular/material/core'; | ||
| import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations'; | ||
| import {MDCCheckboxAdapter, MDCCheckboxFoundation} from '@material/checkbox'; | ||
|
|
@@ -228,12 +232,28 @@ export class MatCheckbox implements AfterViewInit, OnDestroy, ControlValueAccess | |
| private _changeDetectorRef: ChangeDetectorRef, | ||
| private _platform: Platform, | ||
| @Attribute('tabindex') tabIndex: string, | ||
| /** | ||
| * @deprecated `_clickAction` parameter to be removed, use | ||
| * `MAT_CHECKBOX_DEFAULT_OPTIONS` | ||
| * @breaking-change 10.0.0 | ||
| */ | ||
| @Optional() @Inject(MAT_CHECKBOX_CLICK_ACTION) private _clickAction: MatCheckboxClickAction, | ||
| @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) { | ||
| this.tabIndex = parseInt(tabIndex) || 0; | ||
| this._checkboxFoundation = new MDCCheckboxFoundation(this._checkboxAdapter); | ||
| @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string, | ||
| @Optional() @Inject(MAT_CHECKBOX_DEFAULT_OPTIONS) | ||
| private _options?: MatCheckboxDefaultOptions) { | ||
| // Note: We don't need to set up the MDCFormFieldFoundation. Its only purpose is to manage the | ||
| // ripple, which we do ourselves instead. | ||
| this.tabIndex = parseInt(tabIndex) || 0; | ||
| this._checkboxFoundation = new MDCCheckboxFoundation(this._checkboxAdapter); | ||
|
|
||
| this._options = this._options || {}; | ||
|
|
||
| if (this._options.color) { | ||
| this.color = this._options.color; | ||
| } | ||
|
|
||
| // TODO: Remove this after the `_clickAction` parameter is removed as an injection parameter. | ||
|
||
| this._clickAction = this._clickAction || this._options.clickAction; | ||
| } | ||
|
|
||
| ngAfterViewInit() { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only using the options in the constructor so you don't need to create a property for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, though it does make it a little nicer for the following lines where I directly access
this._optionsinstead of adding anif(this._options) { ... }check before them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use default parameters on constructors that get DI'd? i.e.:
@Optional() @Inject(MAT_CHECKBOX_DEFAULT_OPTIONS) private _options: MatCheckboxDefaultOptions = {}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not, Angular will inject
nullif it's not provided: https://stackblitz.com/edit/angular-euxmcx?file=src/app/app.component.ts