File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -909,6 +909,21 @@ describe('MatCheckbox', () => {
909
909
expect ( secondId ) . toMatch ( / m a t - c h e c k b o x - \d + - i n p u t / ) ;
910
910
expect ( firstId ) . not . toEqual ( secondId ) ;
911
911
} ) ;
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
+ } ) ;
912
927
} ) ;
913
928
914
929
describe ( 'with ngModel' , ( ) => {
Original file line number Diff line number Diff line change @@ -425,8 +425,12 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
425
425
}
426
426
427
427
/** 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
+ }
430
434
}
431
435
432
436
_onInteractionEvent ( event : Event ) {
You can’t perform that action at this time.
0 commit comments