Skip to content

Commit 3d2f709

Browse files
rafaelss95tinayuangao
authored andcommitted
docs: add types to public methods and getters/setters (#9612)
1 parent 5290bd8 commit 3d2f709

File tree

20 files changed

+239
-287
lines changed

20 files changed

+239
-287
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export function getMatAutocompleteMissingPanelError(): Error {
118118
export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
119119
private _overlayRef: OverlayRef | null;
120120
private _portal: TemplatePortal;
121-
private _panelOpen: boolean = false;
122121
private _componentDestroyed = false;
123122

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

160159
/** Whether or not the autocomplete panel is open. */
161-
get panelOpen(): boolean {
162-
return this._panelOpen && this.autocomplete.showPanel;
163-
}
160+
get panelOpen(): boolean { return this._panelOpen && this.autocomplete.showPanel; }
161+
private _panelOpen: boolean = false;
164162

165163
/** Opens the autocomplete suggestion panel. */
166164
openPanel(): void {
@@ -252,42 +250,22 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
252250
}));
253251
}
254252

255-
/**
256-
* Sets the autocomplete's value. Part of the ControlValueAccessor interface
257-
* required to integrate with Angular's core forms API.
258-
*
259-
* @param value New value to be written to the model.
260-
*/
253+
// Implemented as part of ControlValueAccessor.
261254
writeValue(value: any): void {
262255
Promise.resolve(null).then(() => this._setTriggerValue(value));
263256
}
264257

265-
/**
266-
* Saves a callback function to be invoked when the autocomplete's value
267-
* changes from user input. Part of the ControlValueAccessor interface
268-
* required to integrate with Angular's core forms API.
269-
*
270-
* @param fn Callback to be triggered when the value changes.
271-
*/
258+
// Implemented as part of ControlValueAccessor.
272259
registerOnChange(fn: (value: any) => {}): void {
273260
this._onChange = fn;
274261
}
275262

276-
/**
277-
* Saves a callback function to be invoked when the autocomplete is blurred
278-
* by the user. Part of the ControlValueAccessor interface required
279-
* to integrate with Angular's core forms API.
280-
*
281-
* @param fn Callback to be triggered when the component has been touched.
282-
*/
263+
// Implemented as part of ControlValueAccessor.
283264
registerOnTouched(fn: () => {}) {
284265
this._onTouched = fn;
285266
}
286267

287-
/**
288-
* Disables the input. Implemented as a part of `ControlValueAccessor`.
289-
* @param isDisabled Whether the component should be disabled.
290-
*/
268+
// Implemented as part of ControlValueAccessor.
291269
setDisabledState(isDisabled: boolean) {
292270
this._element.nativeElement.disabled = isDisabled;
293271
}

src/lib/autocomplete/autocomplete.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC
8989
_keyManager: ActiveDescendantKeyManager<MatOption>;
9090

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

9494
/** Whether the autocomplete panel is open. */
95-
get isOpen(): boolean {
96-
return this._isOpen && this.showPanel;
97-
}
95+
get isOpen(): boolean { return this._isOpen && this.showPanel; }
9896
_isOpen: boolean = false;
9997

10098
/** @docs-private */
@@ -133,9 +131,9 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC
133131
* inside the overlay container to allow for easy styling.
134132
*/
135133
@Input('class')
136-
set classList(classList: string) {
137-
if (classList && classList.length) {
138-
classList.split(' ').forEach(className => this._classList[className.trim()] = true);
134+
set classList(value: string) {
135+
if (value && value.length) {
136+
value.split(' ').forEach(className => this._classList[className.trim()] = true);
139137
this._elementRef.nativeElement.className = '';
140138
}
141139
}

src/lib/button-toggle/button-toggle.ts

Lines changed: 25 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,6 @@ export class MatButtonToggleChange {
7373
})
7474
export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
7575
implements ControlValueAccessor, CanDisable {
76-
77-
/** The value for the button toggle group. Should match currently selected button toggle. */
78-
private _value: any = null;
79-
80-
/** The HTML name attribute applied to toggles in this group. */
81-
private _name: string = `mat-button-toggle-group-${_uniqueIdCounter++}`;
82-
83-
/** Whether the button toggle group should be vertical. */
84-
private _vertical: boolean = false;
85-
86-
/** The currently selected button toggle, should match the value. */
87-
private _selected: MatButtonToggle | null = null;
88-
8976
/**
9077
* The method to be called in order to update ngModel.
9178
* Now `ngModel` binding is not supported in multiple selection mode.
@@ -105,22 +92,25 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
10592
this._name = value;
10693
this._updateButtonToggleNames();
10794
}
95+
private _name: string = `mat-button-toggle-group-${_uniqueIdCounter++}`;
10896

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

114103
/** Value of the toggle group. */
115104
@Input()
116105
get value(): any { return this._value; }
117-
set value(newValue: any) {
118-
if (this._value != newValue) {
119-
this._value = newValue;
120-
this.valueChange.emit(newValue);
106+
set value(value: any) {
107+
if (this._value != value) {
108+
this._value = value;
109+
this.valueChange.emit(value);
121110
this._updateSelectedButtonToggleFromValue();
122111
}
123112
}
113+
private _value: any = null;
124114

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

132-
/** Whether the toggle group is selected. */
122+
/** The currently selected button toggle, should match the value. */
133123
@Input()
134124
get selected(): MatButtonToggle | null { return this._selected; }
135125
set selected(selected: MatButtonToggle | null) {
@@ -140,6 +130,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
140130
selected.checked = true;
141131
}
142132
}
133+
private _selected: MatButtonToggle | null = null;
143134

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

188-
/**
189-
* Sets the model value. Implemented as part of ControlValueAccessor.
190-
* @param value Value to be set to the model.
191-
*/
179+
// Implemented as part of ControlValueAccessor.
192180
writeValue(value: any) {
193181
this.value = value;
194182
this._changeDetector.markForCheck();
195183
}
196184

197-
/**
198-
* Registers a callback that will be triggered when the value has changed.
199-
* Implemented as part of ControlValueAccessor.
200-
* @param fn On change callback function.
201-
*/
185+
// Implemented as part of ControlValueAccessor.
202186
registerOnChange(fn: (value: any) => void) {
203187
this._controlValueAccessorChangeFn = fn;
204188
}
205189

206-
/**
207-
* Registers a callback that will be triggered when the control has been touched.
208-
* Implemented as part of ControlValueAccessor.
209-
* @param fn On touch callback function.
210-
*/
190+
// Implemented as part of ControlValueAccessor.
211191
registerOnTouched(fn: any) {
212192
this._onTouched = fn;
213193
}
214194

215-
/**
216-
* Toggles the disabled state of the component. Implemented as part of ControlValueAccessor.
217-
* @param isDisabled Whether the component should be disabled.
218-
*/
195+
// Implemented as part of ControlValueAccessor.
219196
setDisabledState(isDisabled: boolean): void {
220197
this.disabled = isDisabled;
221198
this._markButtonTogglesForCheck();
@@ -241,16 +218,11 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
241218
})
242219
export class MatButtonToggleGroupMultiple extends _MatButtonToggleGroupMixinBase
243220
implements CanDisable {
244-
245-
/** Whether the button toggle group should be vertical. */
246-
private _vertical: boolean = false;
247-
248221
/** Whether the toggle group is vertical. */
249222
@Input()
250223
get vertical(): boolean { return this._vertical; }
251-
set vertical(value) {
252-
this._vertical = coerceBooleanProperty(value);
253-
}
224+
set vertical(value: boolean) { this._vertical = coerceBooleanProperty(value); }
225+
private _vertical: boolean = false;
254226
}
255227

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

286-
/** Whether or not this button toggle is checked. */
287-
private _checked: boolean = false;
288-
289258
/** Type of the button toggle. Either 'radio' or 'checkbox'. */
290259
_type: ToggleType;
291260

292-
/** Whether or not this button toggle is disabled. */
293-
private _disabled: boolean = false;
294-
295-
/** Value assigned to this button toggle. */
296-
private _value: any = null;
297-
298261
/** Whether or not the button toggle is a single selection. */
299262
private _isSingleSelector: boolean = false;
300263

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

331-
this._checked = newCheckedState;
294+
this._checked = value;
332295

333-
if (newCheckedState && this._isSingleSelector && this.buttonToggleGroup.value != this.value) {
296+
if (value && this._isSingleSelector && this.buttonToggleGroup.value != this.value) {
334297
this.buttonToggleGroup.selected = this;
335298
}
336299
}
300+
private _checked: boolean = false;
337301

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

350315
/** Whether the button is disabled. */
351316
@Input()
352317
get disabled(): boolean {
353318
return this._disabled || (this.buttonToggleGroup != null && this.buttonToggleGroup.disabled) ||
354319
(this.buttonToggleGroupMultiple != null && this.buttonToggleGroupMultiple.disabled);
355320
}
356-
set disabled(value: boolean) {
357-
this._disabled = coerceBooleanProperty(value);
358-
}
321+
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); }
322+
private _disabled: boolean = false;
359323

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

405369
/** Focuses the button. */
406-
focus() {
370+
focus(): void {
407371
this._inputElement.nativeElement.focus();
408372
}
409373

@@ -454,7 +418,7 @@ export class MatButtonToggle implements OnInit, OnDestroy {
454418
}
455419

456420
// Unregister buttonToggleDispatcherListener on destroy
457-
ngOnDestroy(): void {
421+
ngOnDestroy() {
458422
this._removeUniqueSelectionListener();
459423
}
460424

0 commit comments

Comments
 (0)