-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix: consistently coerce boolean and number properties to the correct type #7283
Changes from 5 commits
ec833b4
fe0f358
be2fefd
f89ae6f
682c2fd
dd67f88
6095c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import {CanDisable, mixinDisabled, UniqueSelectionDispatcher} from '@angular/mat | |
import {Subject} from 'rxjs/Subject'; | ||
import {MatAccordion} from './accordion'; | ||
import {AccordionItem} from './accordion-item'; | ||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | ||
|
||
|
||
// Boilerplate for applying mixins to MatExpansionPanel. | ||
|
@@ -79,8 +80,16 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2, | |
}) | ||
export class MatExpansionPanel extends _MatExpansionPanelMixinBase | ||
implements CanDisable, OnChanges, OnDestroy { | ||
|
||
/** Whether the toggle indicator should be hidden. */ | ||
@Input() hideToggle: boolean = false; | ||
@Input() | ||
get hideToggle(): any { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return this._hideToggle; | ||
} | ||
set hideToggle(value: any) { | ||
this._hideToggle = coerceBooleanProperty(value); | ||
} | ||
private _hideToggle = false; | ||
|
||
/** Stream that emits for changes in `@Input` properties. */ | ||
_inputChanges = new Subject<SimpleChanges>(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ import { | |
ViewChild, | ||
ViewEncapsulation, | ||
} from '@angular/core'; | ||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | ||
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion'; | ||
import {Subscription} from 'rxjs/Subscription'; | ||
import {MatTab} from './tab'; | ||
import {merge} from 'rxjs/observable/merge'; | ||
|
@@ -111,7 +111,7 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn | |
|
||
/** The index of the active tab. */ | ||
@Input() | ||
set selectedIndex(value: number | null) { this._indexToSelect = value; } | ||
set selectedIndex(value: number | null) { this._indexToSelect = coerceNumberProperty(value); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like the author was intentionally trying to allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, in a lot of cases people really do just want number. What if we did this? export function coerceNumberProperty(value: any): number;
export function coerceNumberProperty<D>(value: any, fallback: D): number | D;
export function coerceNumberProperty(value: any, fallbackValue = 0) { ... } It would allow people to get just a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems good to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works well. |
||
get selectedIndex(): number | null { return this._selectedIndex; } | ||
private _selectedIndex: number | null = null; | ||
|
||
|
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.
Don't need to add types to lifecycle methods