Skip to content

Commit 34642ea

Browse files
authored
docs: fill out jsdoc for button, checkbox, and radio (#2252)
* docs: fill out jsdoc for button, checkbox, and radio * Fix bad rename, re-add isAriaDisabled
1 parent b2df2a2 commit 34642ea

File tree

7 files changed

+86
-78
lines changed

7 files changed

+86
-78
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type ToggleType = 'checkbox' | 'radio';
3434
/**
3535
* Provider Expression that allows md-button-toggle-group to register as a ControlValueAccessor.
3636
* This allows it to support [(ngModel)].
37+
* @docs-private
3738
*/
3839
export const MD_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any = {
3940
provide: NG_VALUE_ACCESSOR,
@@ -43,7 +44,7 @@ export const MD_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any = {
4344

4445
var _uniqueIdCounter = 0;
4546

46-
/** A simple change event emitted by either MdButtonToggle or MdButtonToggleGroup. */
47+
/** Change event object emitted by MdButtonToggle. */
4748
export class MdButtonToggleChange {
4849
source: MdButtonToggle;
4950
value: any;

src/lib/button/button.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<span class="md-button-wrapper"><ng-content></ng-content></span>
22
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-button-ripple"
3-
[class.md-button-ripple-round]="isRoundButton()"
4-
[md-ripple-trigger]="getHostElement()"
5-
[md-ripple-color]="isRoundButton() ? 'rgba(255, 255, 255, 0.2)' : ''"
3+
[class.md-button-ripple-round]="_isRoundButton()"
4+
[md-ripple-trigger]="_getHostElement()"
5+
[md-ripple-color]="_isRoundButton() ? 'rgba(255, 255, 255, 0.2)' : ''"
66
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>
77
<!-- the touchstart handler prevents the overlay from capturing the initial tap on touch devices -->
88
<div class="md-button-focus-overlay" (touchstart)="$event.preventDefault()"></div>

src/lib/button/button.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,22 @@ export class MdButton {
4747
private _disableRipple: boolean = false;
4848
private _disabled: boolean = null;
4949

50+
/** Whether the ripple effect for this button is disabled. */
5051
@Input()
5152
get disableRipple() { return this._disableRipple; }
5253
set disableRipple(v) { this._disableRipple = coerceBooleanProperty(v); }
5354

55+
/** Whether the button is disabled. */
5456
@Input()
5557
get disabled() { return this._disabled; }
5658
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value) ? true : null; }
5759

5860
constructor(private _elementRef: ElementRef, private _renderer: Renderer) { }
5961

62+
/** The color of the button. Can be `primary`, `accent`, or `warn`. */
6063
@Input()
61-
get color(): string {
62-
return this._color;
63-
}
64-
65-
set color(value: string) {
66-
this._updateColor(value);
67-
}
64+
get color(): string { return this._color; }
65+
set color(value: string) { this._updateColor(value); }
6866

6967
_setMousedown() {
7068
// We only *show* the focus style when focus has come to the button via the keyboard.
@@ -95,16 +93,16 @@ export class MdButton {
9593
this._isKeyboardFocused = false;
9694
}
9795

98-
/** TODO(hansl): e2e test this function. */
99-
focus() {
96+
/** Focuses the button. */
97+
focus(): void {
10098
this._renderer.invokeElementMethod(this._elementRef.nativeElement, 'focus');
10199
}
102100

103-
getHostElement() {
101+
_getHostElement() {
104102
return this._elementRef.nativeElement;
105103
}
106104

107-
isRoundButton() {
105+
_isRoundButton() {
108106
const el = this._elementRef.nativeElement;
109107
return el.hasAttribute('md-icon-button') ||
110108
el.hasAttribute('md-fab') ||
@@ -122,6 +120,7 @@ export class MdButton {
122120
inputs: ['color', 'disabled', 'disableRipple'],
123121
host: {
124122
'[attr.disabled]': 'disabled',
123+
'[attr.aria-disabled]': '_isAriaDisabled',
125124
'[class.md-button-focus]': '_isKeyboardFocused',
126125
'(mousedown)': '_setMousedown()',
127126
'(focus)': '_setKeyboardFocus()',
@@ -137,14 +136,13 @@ export class MdAnchor extends MdButton {
137136
super(elementRef, renderer);
138137
}
139138

139+
/** @docs-private */
140140
@HostBinding('tabIndex')
141141
get tabIndex(): number {
142142
return this.disabled ? -1 : 0;
143143
}
144144

145-
/** Gets the aria-disabled value for the component, which must be a string for Dart. */
146-
@HostBinding('attr.aria-disabled')
147-
get isAriaDisabled(): string {
145+
get _isAriaDisabled(): string {
148146
return this.disabled ? 'true' : 'false';
149147
}
150148

src/lib/checkbox/checkbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(change)="_onInteractionEvent($event)"
1717
(click)="_onInputClick($event)">
1818
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-checkbox-ripple"
19-
[md-ripple-trigger]="getHostElement()"
19+
[md-ripple-trigger]="_getHostElement()"
2020
[md-ripple-centered]="true"
2121
[md-ripple-speed-factor]="0.3"
2222
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>

src/lib/checkbox/checkbox.ts

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import {MdRippleModule, DefaultStyleCompatibilityModeModule} from '../core';
2020
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
2121

2222

23-
/**
24-
* Monotonically increasing integer used to auto-generate unique ids for checkbox components.
25-
*/
23+
/** Monotonically increasing integer used to auto-generate unique ids for checkbox components. */
2624
let nextId = 0;
2725

2826
/**
29-
* Provider Expression that allows md-checkbox to register as a ControlValueAccessor. This allows it
30-
* to support [(ngModel)].
27+
* Provider Expression that allows md-checkbox to register as a ControlValueAccessor.
28+
* This allows it to support [(ngModel)].
29+
* @docs-private
3130
*/
3231
export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
3332
provide: NG_VALUE_ACCESSOR,
@@ -37,6 +36,7 @@ export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
3736

3837
/**
3938
* Represents the different states that require custom transitions between them.
39+
* @docs-private
4040
*/
4141
export enum TransitionCheckState {
4242
/** The initial state of the component before any user interaction. */
@@ -49,7 +49,7 @@ export enum TransitionCheckState {
4949
Indeterminate
5050
}
5151

52-
// A simple change event emitted by the MdCheckbox component.
52+
/** Change event object emitted by MdCheckbox. */
5353
export class MdCheckboxChange {
5454
source: MdCheckbox;
5555
checked: boolean;
@@ -73,7 +73,7 @@ export class MdCheckboxChange {
7373
'[class.md-checkbox-checked]': 'checked',
7474
'[class.md-checkbox-disabled]': 'disabled',
7575
'[class.md-checkbox-align-end]': 'align == "end"',
76-
'[class.md-checkbox-focused]': 'hasFocus',
76+
'[class.md-checkbox-focused]': '_hasFocus',
7777
},
7878
providers: [MD_CHECKBOX_CONTROL_VALUE_ACCESSOR],
7979
encapsulation: ViewEncapsulation.None,
@@ -97,18 +97,19 @@ export class MdCheckbox implements ControlValueAccessor {
9797
/** Whether the ripple effect on click should be disabled. */
9898
private _disableRipple: boolean;
9999

100+
/** Whether the ripple effect for this checkbox is disabled. */
100101
@Input()
101102
get disableRipple(): boolean { return this._disableRipple; }
102103
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
103104

104-
/** ID to be applied to the `input` element */
105+
/** ID of the native input element inside `<md-checkbox>` */
105106
get inputId(): string {
106107
return `input-${this.id}`;
107108
}
108109

109110
private _required: boolean;
110111

111-
/** Whether the checkbox is required or not. */
112+
/** Whether the checkbox is required. */
112113
@Input()
113114
get required(): boolean { return this._required; }
114115
set required(value) { this._required = coerceBooleanProperty(value); }
@@ -118,18 +119,12 @@ export class MdCheckbox implements ControlValueAccessor {
118119

119120
private _disabled: boolean = false;
120121

121-
/**
122-
* Whether the checkbox is disabled. When the checkbox is disabled it cannot be interacted with.
123-
* The correct ARIA attributes are applied to denote this to assistive technology.
124-
*/
122+
/** Whether the checkbox is disabled. */
125123
@Input()
126124
get disabled(): boolean { return this._disabled; }
127125
set disabled(value) { this._disabled = coerceBooleanProperty(value); }
128126

129-
/**
130-
* The tabindex attribute for the checkbox. Note that when the checkbox is disabled, the attribute
131-
* on the host element will be removed. It will be placed back when the checkbox is re-enabled.
132-
*/
127+
/** @docs-private */
133128
@Input() tabindex: number = 0;
134129

135130
/** Name value will be applied to the input element if present */
@@ -141,7 +136,10 @@ export class MdCheckbox implements ControlValueAccessor {
141136
/** The native `<input type=checkbox> element */
142137
@ViewChild('input') _inputElement: ElementRef;
143138

144-
/** Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor. */
139+
/**
140+
* Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor.
141+
* @docs-private
142+
*/
145143
onTouched: () => any = () => {};
146144

147145
private _currentAnimationClass: string = '';
@@ -156,7 +154,7 @@ export class MdCheckbox implements ControlValueAccessor {
156154

157155
private _controlValueAccessorChangeFn: (value: any) => void = (value) => {};
158156

159-
hasFocus: boolean = false;
157+
_hasFocus: boolean = false;
160158

161159
constructor(private _renderer: Renderer,
162160
private _elementRef: ElementRef,
@@ -205,15 +203,10 @@ export class MdCheckbox implements ControlValueAccessor {
205203
}
206204
}
207205

208-
/** Sets the color of the checkbox */
206+
/** The color of the button. Can be `primary`, `accent`, or `warn`. */
209207
@Input()
210-
get color(): string {
211-
return this._color;
212-
}
213-
214-
set color(value: string) {
215-
this._updateColor(value);
216-
}
208+
get color(): string { return this._color; }
209+
set color(value: string) { this._updateColor(value); }
217210

218211
_updateColor(newColor: string) {
219212
this._setElementColor(this._color, false);
@@ -283,19 +276,17 @@ export class MdCheckbox implements ControlValueAccessor {
283276

284277
/** Informs the component when the input has focus so that we can style accordingly */
285278
_onInputFocus() {
286-
this.hasFocus = true;
279+
this._hasFocus = true;
287280
}
288281

289282
/** Informs the component when we lose focus in order to style accordingly */
290283
_onInputBlur() {
291-
this.hasFocus = false;
284+
this._hasFocus = false;
292285
this.onTouched();
293286
}
294287

295-
/**
296-
* Toggles the `checked` value between true and false
297-
*/
298-
toggle() {
288+
/** Toggles the `checked` state of the checkbox. */
289+
toggle(): void {
299290
this.checked = !this.checked;
300291
}
301292

@@ -320,7 +311,8 @@ export class MdCheckbox implements ControlValueAccessor {
320311
}
321312
}
322313

323-
focus() {
314+
/** Focuses the checkbox. */
315+
focus(): void {
324316
this._renderer.invokeElementMethod(this._inputElement.nativeElement, 'focus');
325317
this._onInputFocus();
326318
}
@@ -366,7 +358,7 @@ export class MdCheckbox implements ControlValueAccessor {
366358
return `md-checkbox-anim-${animSuffix}`;
367359
}
368360

369-
getHostElement() {
361+
_getHostElement() {
370362
return this._elementRef.nativeElement;
371363
}
372364
}

src/lib/radio/radio.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="md-radio-outer-circle"></div>
77
<div class="md-radio-inner-circle"></div>
88
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-radio-ripple"
9-
[md-ripple-trigger]="getHostElement()"
9+
[md-ripple-trigger]="_getHostElement()"
1010
[md-ripple-centered]="true"
1111
[md-ripple-speed-factor]="0.3"
1212
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>
@@ -25,7 +25,7 @@
2525
(click)="_onInputClick($event)">
2626

2727
<!-- The label content for radio control. -->
28-
<div class="md-radio-label-content" [class.md-radio-align-end]="align == 'end'">
28+
<div class="md-radio-label-content" [class.md-radio-align-end]="align == 'after'">
2929
<ng-content></ng-content>
3030
</div>
3131
</label>

0 commit comments

Comments
 (0)