File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -909,6 +909,21 @@ describe('MatCheckbox', () => {
909909 expect ( secondId ) . toMatch ( / m a t - c h e c k b o x - \d + - i n p u t / ) ;
910910 expect ( firstId ) . not . toEqual ( secondId ) ;
911911 } ) ;
912+
913+ it ( 'should not change focus origin if origin not specified' , ( ) => {
914+ let [ firstCheckboxDebugEl , secondCheckboxDebugEl ] =
915+ fixture . debugElement . queryAll ( By . directive ( MatCheckbox ) ) ;
916+ fixture . detectChanges ( ) ;
917+
918+ const firstCheckboxInstance = firstCheckboxDebugEl . componentInstance as MatCheckbox ;
919+ const secondCheckboxInstance = secondCheckboxDebugEl . componentInstance as MatCheckbox ;
920+
921+ firstCheckboxInstance . focus ( 'mouse' ) ;
922+ secondCheckboxInstance . focus ( ) ;
923+
924+ expect ( secondCheckboxDebugEl . nativeElement . classList ) . toContain ( 'cdk-focused' ) ;
925+ expect ( secondCheckboxDebugEl . nativeElement . classList ) . toContain ( 'cdk-mouse-focused' ) ;
926+ } ) ;
912927 } ) ;
913928
914929 describe ( 'with ngModel' , ( ) => {
Original file line number Diff line number Diff line change @@ -425,8 +425,12 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
425425 }
426426
427427 /** Focuses the checkbox. */
428- focus ( origin : FocusOrigin = 'keyboard' , options ?: FocusOptions ) : void {
429- this . _focusMonitor . focusVia ( this . _inputElement , origin , options ) ;
428+ focus ( origin ?: FocusOrigin , options ?: FocusOptions ) : void {
429+ if ( origin ) {
430+ this . _focusMonitor . focusVia ( this . _inputElement , origin , options ) ;
431+ } else {
432+ this . _inputElement . nativeElement . focus ( options ) ;
433+ }
430434 }
431435
432436 _onInteractionEvent ( event : Event ) {
You can’t perform that action at this time.
0 commit comments