Skip to content

chore(slide-toggle): add initial documentation of properties #2261

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
Dec 20, 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
2 changes: 1 addition & 1 deletion src/lib/slide-toggle/slide-toggle.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>

<input #input class="md-slide-toggle-input cdk-visually-hidden" type="checkbox"
[id]="getInputId()"
[id]="inputId"
[required]="required"
[tabIndex]="tabIndex"
[checked]="checked"
Expand Down
20 changes: 18 additions & 2 deletions src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,37 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
// Needs to be public to support AOT compilation (as host binding).
_hasFocus: boolean = false;

/** Name value will be applied to the input element if present */
@Input() name: string = null;

/** A unique id for the slide-toggle input. If none is supplied, it will be auto-generated. */
@Input() id: string = this._uniqueId;

/** Used to specify the tabIndex value for the underlying input element. */
@Input() tabIndex: number = 0;

/** Used to set the aria-label attribute on the underlying input element. */
@Input() ariaLabel: string = null;

/** Used to set the aria-labelledby attribute on the underlying input element. */
@Input() ariaLabelledby: string = null;

/** Whether the slide-toggle is disabled. */
@Input()
get disabled(): boolean { return this._disabled; }
set disabled(value) { this._disabled = coerceBooleanProperty(value); }

/** Whether the slide-toggle is required. */
@Input()
get required(): boolean { return this._required; }
set required(value) { this._required = coerceBooleanProperty(value); }

private _change: EventEmitter<MdSlideToggleChange> = new EventEmitter<MdSlideToggleChange>();
/** An event will be dispatched each time the slide-toggle changes its value. */
@Output() change: Observable<MdSlideToggleChange> = this._change.asObservable();

// Returns the unique id for the visual hidden input.
getInputId = () => `${this.id || this._uniqueId}-input`;
/** Returns the unique id for the visual hidden input. */
get inputId(): string { return `${this.id || this._uniqueId}-input`; }

@ViewChild('input') _inputElement: ElementRef;

Expand Down Expand Up @@ -177,11 +189,13 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
this.disabled = isDisabled;
}

/** Focuses the slide-toggle. */
focus() {
this._renderer.invokeElementMethod(this._inputElement.nativeElement, 'focus');
this._onInputFocus();
}

/** Whether the slide-toggle is checked. */
@Input()
get checked() {
return !!this._checked;
Expand All @@ -194,6 +208,7 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
}
}

/** The color of the slide-toggle. Can be primary, accent, or warn. */
@Input()
get color(): string {
return this._color;
Expand All @@ -203,6 +218,7 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
this._updateColor(value);
}

/** Toggles the checked state of the slide-toggle. */
toggle() {
this.checked = !this.checked;
}
Expand Down