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

This commit is contained in:
Juliano
2018-01-23 13:49:59 -02:00
committed by Jeremy Elbourn
parent b3f8a42321
commit 2d592a5879
2 changed files with 20 additions and 0 deletions
+5
View File
@@ -53,6 +53,11 @@ Label <mat-slider #slidey aria-label="Basic slider"></mat-slider>
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>
+15
View File
@@ -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 = () => {};
@@ -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