Skip to content

Commit

Permalink
feat(material/stepper): allow focus origin to be optional input in fo…
Browse files Browse the repository at this point in the history
…cus method (#20914)

Co-authored-by: Jessica Xu <jessicacxu@google.com>
  • Loading branch information
Jessica Xu and jesscxu committed Nov 3, 2020
1 parent 513bfa4 commit a3b5fe3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/material/stepper/step-header.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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. */
Expand Down
13 changes: 13 additions & 0 deletions src/material/stepper/stepper.spec.ts
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/stepper.d.ts
Expand Up @@ -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<MatStepHeader, "mat-step-header", never, { "color": "color"; "state": "state"; "label": "label"; "errorMessage": "errorMessage"; "iconOverrides": "iconOverrides"; "index": "index"; "selected": "selected"; "active": "active"; "optional": "optional"; "disableRipple": "disableRipple"; }, {}, never, never>;
Expand Down

0 comments on commit a3b5fe3

Please sign in to comment.