From 5f4f9442db07a9324ac71e12f8728191d02e81a4 Mon Sep 17 00:00:00 2001 From: Jessica Xu Date: Wed, 28 Oct 2020 14:53:41 -0700 Subject: [PATCH] feat(material/stepper): allow focus origin to be optional input in focus method --- src/material/stepper/step-header.ts | 10 +++++++--- src/material/stepper/stepper.spec.ts | 13 +++++++++++++ tools/public_api_guard/material/stepper.d.ts | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/material/stepper/step-header.ts b/src/material/stepper/step-header.ts index 2f1b3d5c0bbc..8431e373e295 100644 --- a/src/material/stepper/step-header.ts +++ b/src/material/stepper/step-header.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {FocusMonitor} from '@angular/cdk/a11y'; +import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y'; import { ChangeDetectionStrategy, ChangeDetectorRef, @@ -99,8 +99,12 @@ export class MatStepHeader extends _MatStepHeaderMixinBase implements AfterViewI } /** Focuses the step header. */ - focus() { - this._focusMonitor.focusVia(this._elementRef, 'program'); + focus(origin?: FocusOrigin, options?: FocusOptions) { + if (origin) { + this._focusMonitor.focusVia(this._elementRef, origin, options); + } else { + this._elementRef.nativeElement.focus(options); + } } /** Returns string label of given step if it is a text label. */ diff --git a/src/material/stepper/stepper.spec.ts b/src/material/stepper/stepper.spec.ts index 04377c66c563..150a42f3e696 100644 --- a/src/material/stepper/stepper.spec.ts +++ b/src/material/stepper/stepper.spec.ts @@ -881,6 +881,19 @@ describe('MatStepper', () => { expect(headerRipples.every(ripple => ripple.disabled)).toBe(true); }); + it('should be able to disable ripples', () => { + const fixture = createComponent(SimpleMatVerticalStepperApp); + fixture.detectChanges(); + + const stepHeaders = fixture.debugElement.queryAll(By.directive(MatStepHeader)); + + stepHeaders[0].componentInstance.focus('mouse'); + stepHeaders[1].componentInstance.focus(); + + expect(stepHeaders[1].nativeElement.classList).toContain('cdk-focused'); + expect(stepHeaders[1].nativeElement.classList).toContain('cdk-mouse-focused'); + }); + it('should be able to set the theme for all steps', () => { const fixture = createComponent(SimpleMatVerticalStepperApp); fixture.detectChanges(); diff --git a/tools/public_api_guard/material/stepper.d.ts b/tools/public_api_guard/material/stepper.d.ts index ac4bd4f01dec..2fcca89edde8 100644 --- a/tools/public_api_guard/material/stepper.d.ts +++ b/tools/public_api_guard/material/stepper.d.ts @@ -44,7 +44,7 @@ export declare class MatStepHeader extends _MatStepHeaderMixinBase implements Af _getIconContext(): MatStepperIconContext; _stringLabel(): string | null; _templateLabel(): MatStepLabel | null; - focus(): void; + focus(origin?: FocusOrigin, options?: FocusOptions): void; ngAfterViewInit(): void; ngOnDestroy(): void; static ɵcmp: i0.ɵɵComponentDefWithMeta;