Skip to content

feat(slider): add focus and blur methods do MatSlider class #9373

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
Jan 23, 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
5 changes: 5 additions & 0 deletions src/demo-app/slider/slider-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ <h1>Inverted vertical slider</h1>
aria-label="Inverted vertical slider">
</mat-slider>

<h1>Set/lost focus to show thumblabel programmatically</h1>
<mat-slider #demoSlider="matSlider" thumbLabel aria-label="Slider with thumb label"></mat-slider>
<button (click)="demoSlider.focus()">Focus Slider</button>
<button (click)="demoSlider.blur()">Blur Slider</button>

<mat-tab-group>
<mat-tab label="One">
<mat-slider min="1" max="5" value="3" aria-label="Slider in a tab"></mat-slider>
Expand Down
15 changes: 15 additions & 0 deletions src/lib/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ export class MatSlider extends _MatSliderMixinBase
return this.value || 0;
}

/** set focus to the host element */
focus() {
this._focusHostElement();
}

/** blur the host element */
blur() {
this._blurHostElement();
}

/** onTouch function registered via registerOnTouch (ControlValueAccessor). */
onTouched: () => any = () => {};

Expand Down Expand Up @@ -691,6 +701,11 @@ export class MatSlider extends _MatSliderMixinBase
this._elementRef.nativeElement.focus();
}

/** Blurs the native element. */
private _blurHostElement() {
this._elementRef.nativeElement.blur();
}

/**
* Sets the model value. Implemented as part of ControlValueAccessor.
* @param value
Expand Down