File tree Expand file tree Collapse file tree 4 files changed +22
-1
lines changed
tools/public_api_guard/material Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 22 [class.mdc-form-field--align-end] ="labelPosition == 'before' ">
33 < div class ="mdc-radio " [class.mdc-radio--disabled] ="disabled ">
44 <!-- Render this element first so the input is on top. -->
5- < div class ="mat-mdc-radio-touch-target " (click) ="_onInputInteraction ($event) "> </ div >
5+ < div class ="mat-mdc-radio-touch-target " (click) ="_onTouchTargetClick ($event) "> </ div >
66 < input #input class ="mdc-radio__native-control " type ="radio "
77 [id] ="inputId "
88 [checked] ="checked "
Original file line number Diff line number Diff line change @@ -807,6 +807,15 @@ describe('MDC-based MatRadio', () => {
807807 }
808808 } ) ;
809809
810+ it ( 'should focus on underlying input element when clicking on the touch target' , ( ) => {
811+ const input = radioDebugElements [ 0 ] . nativeElement . querySelector ( 'input' ) ;
812+ expect ( document . activeElement ) . not . toBe ( input ) ;
813+
814+ radioDebugElements [ 0 ] . nativeElement . querySelector ( '.mat-mdc-radio-touch-target' ) . click ( ) ;
815+ fixture . detectChanges ( ) ;
816+ expect ( document . activeElement ) . toBe ( input ) ;
817+ } ) ;
818+
810819 it ( 'should not change focus origin if origin not specified' , ( ) => {
811820 fruitRadioInstances [ 0 ] . focus ( undefined , 'mouse' ) ;
812821 fruitRadioInstances [ 1 ] . focus ( ) ;
Original file line number Diff line number Diff line change @@ -611,6 +611,17 @@ export abstract class _MatRadioButtonBase
611611 }
612612 }
613613
614+ /** Triggered when the user clicks on the touch target. */
615+ _onTouchTargetClick ( event : Event ) {
616+ this . _onInputInteraction ( event ) ;
617+
618+ if ( ! this . disabled ) {
619+ // Normally the input should be focused already, but if the click
620+ // comes from the touch target, then we might have to focus it ourselves.
621+ this . _inputElement . nativeElement . focus ( ) ;
622+ }
623+ }
624+
614625 /** Sets the disabled state and marks for check if a change occurred. */
615626 protected _setDisabled ( value : boolean ) {
616627 if ( this . _disabled !== value ) {
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ export abstract class _MatRadioButtonBase extends _MatRadioButtonMixinBase imple
8686 // (undocumented)
8787 _onInputClick(event : Event ): void ;
8888 _onInputInteraction(event : Event ): void ;
89+ _onTouchTargetClick(event : Event ): void ;
8990 radioGroup: _MatRadioGroupBase <_MatRadioButtonBase >;
9091 get required(): boolean ;
9192 set required(value : BooleanInput );
You can’t perform that action at this time.
0 commit comments