Skip to content

Commit a3b5fe3

Browse files
Jessica Xujesscxu
Jessica Xu
andauthored
feat(material/stepper): allow focus origin to be optional input in focus method (#20914)
Co-authored-by: Jessica Xu <[email protected]>
1 parent 513bfa4 commit a3b5fe3

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/material/stepper/step-header.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {FocusMonitor} from '@angular/cdk/a11y';
9+
import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
1010
import {
1111
ChangeDetectionStrategy,
1212
ChangeDetectorRef,
@@ -99,8 +99,12 @@ export class MatStepHeader extends _MatStepHeaderMixinBase implements AfterViewI
9999
}
100100

101101
/** Focuses the step header. */
102-
focus() {
103-
this._focusMonitor.focusVia(this._elementRef, 'program');
102+
focus(origin?: FocusOrigin, options?: FocusOptions) {
103+
if (origin) {
104+
this._focusMonitor.focusVia(this._elementRef, origin, options);
105+
} else {
106+
this._elementRef.nativeElement.focus(options);
107+
}
104108
}
105109

106110
/** Returns string label of given step if it is a text label. */

src/material/stepper/stepper.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,19 @@ describe('MatStepper', () => {
881881
expect(headerRipples.every(ripple => ripple.disabled)).toBe(true);
882882
});
883883

884+
it('should be able to disable ripples', () => {
885+
const fixture = createComponent(SimpleMatVerticalStepperApp);
886+
fixture.detectChanges();
887+
888+
const stepHeaders = fixture.debugElement.queryAll(By.directive(MatStepHeader));
889+
890+
stepHeaders[0].componentInstance.focus('mouse');
891+
stepHeaders[1].componentInstance.focus();
892+
893+
expect(stepHeaders[1].nativeElement.classList).toContain('cdk-focused');
894+
expect(stepHeaders[1].nativeElement.classList).toContain('cdk-mouse-focused');
895+
});
896+
884897
it('should be able to set the theme for all steps', () => {
885898
const fixture = createComponent(SimpleMatVerticalStepperApp);
886899
fixture.detectChanges();

tools/public_api_guard/material/stepper.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export declare class MatStepHeader extends _MatStepHeaderMixinBase implements Af
4444
_getIconContext(): MatStepperIconContext;
4545
_stringLabel(): string | null;
4646
_templateLabel(): MatStepLabel | null;
47-
focus(): void;
47+
focus(origin?: FocusOrigin, options?: FocusOptions): void;
4848
ngAfterViewInit(): void;
4949
ngOnDestroy(): void;
5050
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>;

0 commit comments

Comments
 (0)