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 2
2
[class.mdc-form-field--align-end] ="labelPosition == 'before' ">
3
3
< div class ="mdc-radio " [class.mdc-radio--disabled] ="disabled ">
4
4
<!-- 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 >
6
6
< input #input class ="mdc-radio__native-control " type ="radio "
7
7
[id] ="inputId "
8
8
[checked] ="checked "
Original file line number Diff line number Diff line change @@ -807,6 +807,15 @@ describe('MDC-based MatRadio', () => {
807
807
}
808
808
} ) ;
809
809
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
+
810
819
it ( 'should not change focus origin if origin not specified' , ( ) => {
811
820
fruitRadioInstances [ 0 ] . focus ( undefined , 'mouse' ) ;
812
821
fruitRadioInstances [ 1 ] . focus ( ) ;
Original file line number Diff line number Diff line change @@ -611,6 +611,17 @@ export abstract class _MatRadioButtonBase
611
611
}
612
612
}
613
613
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
+
614
625
/** Sets the disabled state and marks for check if a change occurred. */
615
626
protected _setDisabled ( value : boolean ) {
616
627
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
86
86
// (undocumented)
87
87
_onInputClick(event : Event ): void ;
88
88
_onInputInteraction(event : Event ): void ;
89
+ _onTouchTargetClick(event : Event ): void ;
89
90
radioGroup: _MatRadioGroupBase <_MatRadioButtonBase >;
90
91
get required(): boolean ;
91
92
set required(value : BooleanInput );
You can’t perform that action at this time.
0 commit comments