Skip to content

Commit 1ced9e7

Browse files
committed
feat(material/stepper): allow focus origin to be optional input in focus method
1 parent cc503c4 commit 1ced9e7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
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) {
103+
if (origin) {
104+
this._focusMonitor.focusVia(this._elementRef, origin);
105+
} else {
106+
this._elementRef.nativeElement.focus();
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();

0 commit comments

Comments
 (0)