File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,23 @@ describe('MatButton', () => {
8484 expect ( buttonDebugEl . nativeElement . classList ) . toContain ( 'cdk-touch-focused' ) ;
8585 } ) ;
8686
87+ it ( 'should not change focus origin if origin not specified' , ( ) => {
88+ const fixture = TestBed . createComponent ( TestApp ) ;
89+ fixture . detectChanges ( ) ;
90+
91+ const fabButtonDebugEl = fixture . debugElement . query ( By . css ( 'button[mat-fab]' ) ) ! ;
92+ const fabButtonInstance = fabButtonDebugEl . componentInstance as MatButton ;
93+ fabButtonInstance . focus ( 'mouse' ) ;
94+
95+ const miniFabButtonDebugEl = fixture . debugElement . query ( By . css ( 'button[mat-mini-fab]' ) ) ! ;
96+ const miniFabButtonInstance = miniFabButtonDebugEl . componentInstance as MatButton ;
97+
98+ miniFabButtonInstance . focus ( ) ;
99+
100+ expect ( miniFabButtonDebugEl . nativeElement . classList ) . toContain ( 'cdk-focused' ) ;
101+ expect ( miniFabButtonDebugEl . nativeElement . classList ) . toContain ( 'cdk-mouse-focused' ) ;
102+ } ) ;
103+
87104 describe ( 'button[mat-fab]' , ( ) => {
88105 it ( 'should have accent palette by default' , ( ) => {
89106 const fixture = TestBed . createComponent ( TestApp ) ;
Original file line number Diff line number Diff line change @@ -127,8 +127,12 @@ export class MatButton extends _MatButtonMixinBase
127127 }
128128
129129 /** Focuses the button. */
130- focus ( origin : FocusOrigin = 'program' , options ?: FocusOptions ) : void {
131- this . _focusMonitor . focusVia ( this . _getHostElement ( ) , origin , options ) ;
130+ focus ( origin ?: FocusOrigin , options ?: FocusOptions ) : void {
131+ if ( origin ) {
132+ this . _focusMonitor . focusVia ( this . _getHostElement ( ) , origin , options ) ;
133+ } else {
134+ this . _getHostElement ( ) . focus ( options ) ;
135+ }
132136 }
133137
134138 _getHostElement ( ) {
You can’t perform that action at this time.
0 commit comments