mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feat(slider): add focus and blur methods do MatSlider (#9373)
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user