Skip to content

docs: fill out jsdoc for button, checkbox, and radio #2252

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 2 commits into from
Dec 16, 2016
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
3 changes: 2 additions & 1 deletion src/lib/button-toggle/button-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ToggleType = 'checkbox' | 'radio';
/**
* Provider Expression that allows md-button-toggle-group to register as a ControlValueAccessor.
* This allows it to support [(ngModel)].
* @docs-private
*/
export const MD_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
Expand All @@ -43,7 +44,7 @@ export const MD_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR: any = {

var _uniqueIdCounter = 0;

/** A simple change event emitted by either MdButtonToggle or MdButtonToggleGroup. */
/** Change event object emitted by MdButtonToggle. */
export class MdButtonToggleChange {
source: MdButtonToggle;
value: any;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/button/button.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<span class="md-button-wrapper"><ng-content></ng-content></span>
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-button-ripple"
[class.md-button-ripple-round]="isRoundButton()"
[md-ripple-trigger]="getHostElement()"
[md-ripple-color]="isRoundButton() ? 'rgba(255, 255, 255, 0.2)' : ''"
[class.md-button-ripple-round]="_isRoundButton()"
[md-ripple-trigger]="_getHostElement()"
[md-ripple-color]="_isRoundButton() ? 'rgba(255, 255, 255, 0.2)' : ''"
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>
<!-- the touchstart handler prevents the overlay from capturing the initial tap on touch devices -->
<div class="md-button-focus-overlay" (touchstart)="$event.preventDefault()"></div>
26 changes: 12 additions & 14 deletions src/lib/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,22 @@ export class MdButton {
private _disableRipple: boolean = false;
private _disabled: boolean = null;

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

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

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

/** The color of the button. Can be `primary`, `accent`, or `warn`. */
@Input()
get color(): string {
return this._color;
}

set color(value: string) {
this._updateColor(value);
}
get color(): string { return this._color; }
set color(value: string) { this._updateColor(value); }

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

/** TODO(hansl): e2e test this function. */
focus() {
/** Focuses the button. */
focus(): void {
this._renderer.invokeElementMethod(this._elementRef.nativeElement, 'focus');
}

getHostElement() {
_getHostElement() {
return this._elementRef.nativeElement;
}

isRoundButton() {
_isRoundButton() {
const el = this._elementRef.nativeElement;
return el.hasAttribute('md-icon-button') ||
el.hasAttribute('md-fab') ||
Expand All @@ -122,6 +120,7 @@ export class MdButton {
inputs: ['color', 'disabled', 'disableRipple'],
host: {
'[attr.disabled]': 'disabled',
'[attr.aria-disabled]': '_isAriaDisabled',
'[class.md-button-focus]': '_isKeyboardFocused',
'(mousedown)': '_setMousedown()',
'(focus)': '_setKeyboardFocus()',
Expand All @@ -137,14 +136,13 @@ export class MdAnchor extends MdButton {
super(elementRef, renderer);
}

/** @docs-private */
@HostBinding('tabIndex')
get tabIndex(): number {
return this.disabled ? -1 : 0;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/lib/checkbox/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(change)="_onInteractionEvent($event)"
(click)="_onInputClick($event)">
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-checkbox-ripple"
[md-ripple-trigger]="getHostElement()"
[md-ripple-trigger]="_getHostElement()"
[md-ripple-centered]="true"
[md-ripple-speed-factor]="0.3"
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>
Expand Down
62 changes: 27 additions & 35 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import {MdRippleModule, DefaultStyleCompatibilityModeModule} from '../core';
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';


/**
* Monotonically increasing integer used to auto-generate unique ids for checkbox components.
*/
/** Monotonically increasing integer used to auto-generate unique ids for checkbox components. */
let nextId = 0;

/**
* Provider Expression that allows md-checkbox to register as a ControlValueAccessor. This allows it
* to support [(ngModel)].
* Provider Expression that allows md-checkbox to register as a ControlValueAccessor.
* This allows it to support [(ngModel)].
* @docs-private
*/
export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
Expand All @@ -37,6 +36,7 @@ export const MD_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {

/**
* Represents the different states that require custom transitions between them.
* @docs-private
*/
export enum TransitionCheckState {
/** The initial state of the component before any user interaction. */
Expand All @@ -49,7 +49,7 @@ export enum TransitionCheckState {
Indeterminate
}

// A simple change event emitted by the MdCheckbox component.
/** Change event object emitted by MdCheckbox. */
export class MdCheckboxChange {
source: MdCheckbox;
checked: boolean;
Expand All @@ -73,7 +73,7 @@ export class MdCheckboxChange {
'[class.md-checkbox-checked]': 'checked',
'[class.md-checkbox-disabled]': 'disabled',
'[class.md-checkbox-align-end]': 'align == "end"',
'[class.md-checkbox-focused]': 'hasFocus',
'[class.md-checkbox-focused]': '_hasFocus',
},
providers: [MD_CHECKBOX_CONTROL_VALUE_ACCESSOR],
encapsulation: ViewEncapsulation.None,
Expand All @@ -97,18 +97,19 @@ export class MdCheckbox implements ControlValueAccessor {
/** Whether the ripple effect on click should be disabled. */
private _disableRipple: boolean;

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

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

private _required: boolean;

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

private _disabled: boolean = false;

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

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

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

/** Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor. */
/**
* Called when the checkbox is blurred. Needed to properly implement ControlValueAccessor.
* @docs-private
*/
onTouched: () => any = () => {};

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

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

hasFocus: boolean = false;
_hasFocus: boolean = false;

constructor(private _renderer: Renderer,
private _elementRef: ElementRef,
Expand Down Expand Up @@ -205,15 +203,10 @@ export class MdCheckbox implements ControlValueAccessor {
}
}

/** Sets the color of the checkbox */
/** The color of the button. Can be `primary`, `accent`, or `warn`. */
@Input()
get color(): string {
return this._color;
}

set color(value: string) {
this._updateColor(value);
}
get color(): string { return this._color; }
set color(value: string) { this._updateColor(value); }

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

/** Informs the component when the input has focus so that we can style accordingly */
_onInputFocus() {
this.hasFocus = true;
this._hasFocus = true;
}

/** Informs the component when we lose focus in order to style accordingly */
_onInputBlur() {
this.hasFocus = false;
this._hasFocus = false;
this.onTouched();
}

/**
* Toggles the `checked` value between true and false
*/
toggle() {
/** Toggles the `checked` state of the checkbox. */
toggle(): void {
this.checked = !this.checked;
}

Expand All @@ -320,7 +311,8 @@ export class MdCheckbox implements ControlValueAccessor {
}
}

focus() {
/** Focuses the checkbox. */
focus(): void {
this._renderer.invokeElementMethod(this._inputElement.nativeElement, 'focus');
this._onInputFocus();
}
Expand Down Expand Up @@ -366,7 +358,7 @@ export class MdCheckbox implements ControlValueAccessor {
return `md-checkbox-anim-${animSuffix}`;
}

getHostElement() {
_getHostElement() {
return this._elementRef.nativeElement;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/radio/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="md-radio-outer-circle"></div>
<div class="md-radio-inner-circle"></div>
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-radio-ripple"
[md-ripple-trigger]="getHostElement()"
[md-ripple-trigger]="_getHostElement()"
[md-ripple-centered]="true"
[md-ripple-speed-factor]="0.3"
md-ripple-background-color="rgba(0, 0, 0, 0)"></div>
Expand All @@ -25,7 +25,7 @@
(click)="_onInputClick($event)">

<!-- The label content for radio control. -->
<div class="md-radio-label-content" [class.md-radio-align-end]="align == 'end'">
<div class="md-radio-label-content" [class.md-radio-align-end]="align == 'after'">
<ng-content></ng-content>
</div>
</label>
Loading