Skip to content

docs: add types to public methods and getters/setters #9612

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
merged 1 commit into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export function getMatAutocompleteMissingPanelError(): Error {
export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
private _overlayRef: OverlayRef | null;
private _portal: TemplatePortal;
private _panelOpen: boolean = false;
private _componentDestroyed = false;

/** Strategy that is used to position the panel. */
Expand Down Expand Up @@ -158,9 +157,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
}

/** Whether or not the autocomplete panel is open. */
get panelOpen(): boolean {
return this._panelOpen && this.autocomplete.showPanel;
}
get panelOpen(): boolean { return this._panelOpen && this.autocomplete.showPanel; }
private _panelOpen: boolean = false;

/** Opens the autocomplete suggestion panel. */
openPanel(): void {
Expand Down Expand Up @@ -252,42 +250,22 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
}));
}

/**
* Sets the autocomplete's value. Part of the ControlValueAccessor interface
* required to integrate with Angular's core forms API.
*
* @param value New value to be written to the model.
*/
// Implemented as part of ControlValueAccessor.
writeValue(value: any): void {
Promise.resolve(null).then(() => this._setTriggerValue(value));
}

/**
* Saves a callback function to be invoked when the autocomplete's value
* changes from user input. Part of the ControlValueAccessor interface
* required to integrate with Angular's core forms API.
*
* @param fn Callback to be triggered when the value changes.
*/
// Implemented as part of ControlValueAccessor.
registerOnChange(fn: (value: any) => {}): void {
this._onChange = fn;
}

/**
* Saves a callback function to be invoked when the autocomplete is blurred
* by the user. Part of the ControlValueAccessor interface required
* to integrate with Angular's core forms API.
*
* @param fn Callback to be triggered when the component has been touched.
*/
// Implemented as part of ControlValueAccessor.
registerOnTouched(fn: () => {}) {
this._onTouched = fn;
}

/**
* Disables the input. Implemented as a part of `ControlValueAccessor`.
* @param isDisabled Whether the component should be disabled.
*/
// Implemented as part of ControlValueAccessor.
setDisabledState(isDisabled: boolean) {
this._element.nativeElement.disabled = isDisabled;
}
Expand Down
12 changes: 5 additions & 7 deletions src/lib/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC
_keyManager: ActiveDescendantKeyManager<MatOption>;

/** Whether the autocomplete panel should be visible, depending on option length. */
showPanel = false;
showPanel: boolean = false;

/** Whether the autocomplete panel is open. */
get isOpen(): boolean {
return this._isOpen && this.showPanel;
}
get isOpen(): boolean { return this._isOpen && this.showPanel; }
_isOpen: boolean = false;

/** @docs-private */
Expand Down Expand Up @@ -133,9 +131,9 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC
* inside the overlay container to allow for easy styling.
*/
@Input('class')
set classList(classList: string) {
if (classList && classList.length) {
classList.split(' ').forEach(className => this._classList[className.trim()] = true);
set classList(value: string) {
if (value && value.length) {
value.split(' ').forEach(className => this._classList[className.trim()] = true);
this._elementRef.nativeElement.className = '';
}
}
Expand Down
86 changes: 25 additions & 61 deletions src/lib/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,6 @@ export class MatButtonToggleChange {
})
export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
implements ControlValueAccessor, CanDisable {

/** The value for the button toggle group. Should match currently selected button toggle. */
private _value: any = null;

/** The HTML name attribute applied to toggles in this group. */
private _name: string = `mat-button-toggle-group-${_uniqueIdCounter++}`;

/** Whether the button toggle group should be vertical. */
private _vertical: boolean = false;

/** The currently selected button toggle, should match the value. */
private _selected: MatButtonToggle | null = null;

/**
* The method to be called in order to update ngModel.
* Now `ngModel` binding is not supported in multiple selection mode.
Expand All @@ -105,22 +92,25 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
this._name = value;
this._updateButtonToggleNames();
}
private _name: string = `mat-button-toggle-group-${_uniqueIdCounter++}`;

/** Whether the toggle group is vertical. */
@Input()
get vertical(): boolean { return this._vertical; }
set vertical(value: boolean) { this._vertical = coerceBooleanProperty(value); }
private _vertical: boolean = false;

/** Value of the toggle group. */
@Input()
get value(): any { return this._value; }
set value(newValue: any) {
if (this._value != newValue) {
this._value = newValue;
this.valueChange.emit(newValue);
set value(value: any) {
if (this._value != value) {
this._value = value;
this.valueChange.emit(value);
this._updateSelectedButtonToggleFromValue();
}
}
private _value: any = null;

/**
* Event that emits whenever the value of the group changes.
Expand All @@ -129,7 +119,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
*/
@Output() readonly valueChange = new EventEmitter<any>();

/** Whether the toggle group is selected. */
/** The currently selected button toggle, should match the value. */
@Input()
get selected(): MatButtonToggle | null { return this._selected; }
set selected(selected: MatButtonToggle | null) {
Expand All @@ -140,6 +130,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
selected.checked = true;
}
}
private _selected: MatButtonToggle | null = null;

/** Event emitted when the group's value changes. */
@Output() readonly change: EventEmitter<MatButtonToggleChange> =
Expand Down Expand Up @@ -185,37 +176,23 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
this.change.emit(event);
}

/**
* Sets the model value. Implemented as part of ControlValueAccessor.
* @param value Value to be set to the model.
*/
// Implemented as part of ControlValueAccessor.
writeValue(value: any) {
this.value = value;
this._changeDetector.markForCheck();
}

/**
* Registers a callback that will be triggered when the value has changed.
* Implemented as part of ControlValueAccessor.
* @param fn On change callback function.
*/
// Implemented as part of ControlValueAccessor.
registerOnChange(fn: (value: any) => void) {
this._controlValueAccessorChangeFn = fn;
}

/**
* Registers a callback that will be triggered when the control has been touched.
* Implemented as part of ControlValueAccessor.
* @param fn On touch callback function.
*/
// Implemented as part of ControlValueAccessor.
registerOnTouched(fn: any) {
this._onTouched = fn;
}

/**
* Toggles the disabled state of the component. Implemented as part of ControlValueAccessor.
* @param isDisabled Whether the component should be disabled.
*/
// Implemented as part of ControlValueAccessor.
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
this._markButtonTogglesForCheck();
Expand All @@ -241,16 +218,11 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
})
export class MatButtonToggleGroupMultiple extends _MatButtonToggleGroupMixinBase
implements CanDisable {

/** Whether the button toggle group should be vertical. */
private _vertical: boolean = false;

/** Whether the toggle group is vertical. */
@Input()
get vertical(): boolean { return this._vertical; }
set vertical(value) {
this._vertical = coerceBooleanProperty(value);
}
set vertical(value: boolean) { this._vertical = coerceBooleanProperty(value); }
private _vertical: boolean = false;
}

/** Single button inside of a toggle group. */
Expand Down Expand Up @@ -283,18 +255,9 @@ export class MatButtonToggle implements OnInit, OnDestroy {
*/
@Input('aria-labelledby') ariaLabelledby: string | null = null;

/** Whether or not this button toggle is checked. */
private _checked: boolean = false;

/** Type of the button toggle. Either 'radio' or 'checkbox'. */
_type: ToggleType;

/** Whether or not this button toggle is disabled. */
private _disabled: boolean = false;

/** Value assigned to this button toggle. */
private _value: any = null;

/** Whether or not the button toggle is a single selection. */
private _isSingleSelector: boolean = false;

Expand All @@ -321,19 +284,20 @@ export class MatButtonToggle implements OnInit, OnDestroy {
/** Whether the button is checked. */
@Input()
get checked(): boolean { return this._checked; }
set checked(newCheckedState: boolean) {
if (this._isSingleSelector && newCheckedState) {
set checked(value: boolean) {
if (this._isSingleSelector && value) {
// Notify all button toggles with the same name (in the same group) to un-check.
this._buttonToggleDispatcher.notify(this.id, this.name);
this._changeDetectorRef.markForCheck();
}

this._checked = newCheckedState;
this._checked = value;

if (newCheckedState && this._isSingleSelector && this.buttonToggleGroup.value != this.value) {
if (value && this._isSingleSelector && this.buttonToggleGroup.value != this.value) {
this.buttonToggleGroup.selected = this;
}
}
private _checked: boolean = false;

/** MatButtonToggleGroup reads this to assign its own value. */
@Input()
Expand All @@ -346,16 +310,16 @@ export class MatButtonToggle implements OnInit, OnDestroy {
this._value = value;
}
}
private _value: any = null;

/** Whether the button is disabled. */
@Input()
get disabled(): boolean {
return this._disabled || (this.buttonToggleGroup != null && this.buttonToggleGroup.disabled) ||
(this.buttonToggleGroupMultiple != null && this.buttonToggleGroupMultiple.disabled);
}
set disabled(value: boolean) {
this._disabled = coerceBooleanProperty(value);
}
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); }
private _disabled: boolean = false;

/** Event emitted when the group value changes. */
@Output() readonly change: EventEmitter<MatButtonToggleChange> =
Expand Down Expand Up @@ -403,7 +367,7 @@ export class MatButtonToggle implements OnInit, OnDestroy {
}

/** Focuses the button. */
focus() {
focus(): void {
this._inputElement.nativeElement.focus();
}

Expand Down Expand Up @@ -454,7 +418,7 @@ export class MatButtonToggle implements OnInit, OnDestroy {
}

// Unregister buttonToggleDispatcherListener on destroy
ngOnDestroy(): void {
ngOnDestroy() {
this._removeUniqueSelectionListener();
}

Expand Down
Loading