@@ -132,6 +132,29 @@ describe('MDC-based MatRadio', () => {
132
132
}
133
133
} ) ;
134
134
135
+ it ( 'should make all disabled buttons interactive if the group is marked as disabledInteractive' , ( ) => {
136
+ testComponent . isGroupDisabledInteractive = true ;
137
+ fixture . changeDetectorRef . markForCheck ( ) ;
138
+ fixture . detectChanges ( ) ;
139
+ expect ( radioInstances . every ( radio => radio . disabledInteractive ) ) . toBe ( true ) ;
140
+ } ) ;
141
+
142
+ it ( 'should prevent the click action when disabledInteractive and disabled' , ( ) => {
143
+ testComponent . isGroupDisabled = true ;
144
+ testComponent . isGroupDisabledInteractive = true ;
145
+ fixture . changeDetectorRef . markForCheck ( ) ;
146
+ fixture . detectChanges ( ) ;
147
+
148
+ // We can't monitor the `defaultPrevented` state on the
149
+ // native `click` so we dispatch an extra one.
150
+ const fakeEvent = dispatchFakeEvent ( radioInputElements [ 0 ] , 'click' ) ;
151
+ radioInputElements [ 0 ] . click ( ) ;
152
+ fixture . detectChanges ( ) ;
153
+
154
+ expect ( fakeEvent . defaultPrevented ) . toBe ( true ) ;
155
+ expect ( radioInstances [ 0 ] . checked ) . toBe ( false ) ;
156
+ } ) ;
157
+
135
158
it ( 'should set required to each radio button when the group is required' , ( ) => {
136
159
testComponent . isGroupRequired = true ;
137
160
fixture . changeDetectorRef . markForCheck ( ) ;
@@ -675,6 +698,7 @@ describe('MDC-based MatRadio', () => {
675
698
let fixture : ComponentFixture < DisableableRadioButton > ;
676
699
let radioInstance : MatRadioButton ;
677
700
let radioNativeElement : HTMLInputElement ;
701
+ let radioHost : HTMLElement ;
678
702
let testComponent : DisableableRadioButton ;
679
703
680
704
beforeEach ( ( ) => {
@@ -683,8 +707,9 @@ describe('MDC-based MatRadio', () => {
683
707
684
708
testComponent = fixture . debugElement . componentInstance ;
685
709
const radioDebugElement = fixture . debugElement . query ( By . directive ( MatRadioButton ) ) ! ;
710
+ radioHost = radioDebugElement . nativeElement ;
686
711
radioInstance = radioDebugElement . injector . get < MatRadioButton > ( MatRadioButton ) ;
687
- radioNativeElement = radioDebugElement . nativeElement . querySelector ( 'input' ) ;
712
+ radioNativeElement = radioHost . querySelector ( 'input' ) ! ;
688
713
} ) ;
689
714
690
715
it ( 'should toggle the disabled state' , ( ) => {
@@ -703,6 +728,24 @@ describe('MDC-based MatRadio', () => {
703
728
expect ( radioInstance . disabled ) . toBeFalsy ( ) ;
704
729
expect ( radioNativeElement . disabled ) . toBeFalsy ( ) ;
705
730
} ) ;
731
+
732
+ it ( 'should keep the button interactive if disabledInteractive is enabled' , ( ) => {
733
+ testComponent . disabled = true ;
734
+ fixture . changeDetectorRef . markForCheck ( ) ;
735
+ fixture . detectChanges ( ) ;
736
+
737
+ expect ( radioNativeElement . disabled ) . toBe ( true ) ;
738
+ expect ( radioNativeElement . hasAttribute ( 'aria-disabled' ) ) . toBe ( false ) ;
739
+ expect ( radioHost . classList ) . not . toContain ( 'mat-mdc-radio-disabled-interactive' ) ;
740
+
741
+ testComponent . disabledInteractive = true ;
742
+ fixture . changeDetectorRef . markForCheck ( ) ;
743
+ fixture . detectChanges ( ) ;
744
+
745
+ expect ( radioNativeElement . disabled ) . toBe ( false ) ;
746
+ expect ( radioNativeElement . getAttribute ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
747
+ expect ( radioHost . classList ) . toContain ( 'mat-mdc-radio-disabled-interactive' ) ;
748
+ } ) ;
706
749
} ) ;
707
750
708
751
describe ( 'as standalone' , ( ) => {
@@ -1031,11 +1074,13 @@ describe('MatRadioDefaultOverrides', () => {
1031
1074
1032
1075
@Component ( {
1033
1076
template : `
1034
- <mat-radio-group [disabled]="isGroupDisabled"
1035
- [labelPosition]="labelPos"
1036
- [required]="isGroupRequired"
1037
- [value]="groupValue"
1038
- name="test-name">
1077
+ <mat-radio-group
1078
+ [disabled]="isGroupDisabled"
1079
+ [labelPosition]="labelPos"
1080
+ [required]="isGroupRequired"
1081
+ [value]="groupValue"
1082
+ [disabledInteractive]="isGroupDisabledInteractive"
1083
+ name="test-name">
1039
1084
@if (isFirstShown) {
1040
1085
<mat-radio-button value="fire" [disableRipple]="disableRipple" [disabled]="isFirstDisabled"
1041
1086
[color]="color">
@@ -1058,6 +1103,7 @@ class RadiosInsideRadioGroup {
1058
1103
isFirstDisabled = false ;
1059
1104
isGroupDisabled = false ;
1060
1105
isGroupRequired = false ;
1106
+ isGroupDisabledInteractive = false ;
1061
1107
groupValue : string | null = null ;
1062
1108
disableRipple = false ;
1063
1109
color : string | null ;
@@ -1130,16 +1176,18 @@ class RadioGroupWithNgModel {
1130
1176
}
1131
1177
1132
1178
@Component ( {
1133
- template : `<mat-radio-button>One</mat-radio-button>` ,
1179
+ template : `
1180
+ <mat-radio-button
1181
+ [disabled]="disabled"
1182
+ [disabledInteractive]="disabledInteractive">One</mat-radio-button>` ,
1134
1183
standalone : true ,
1135
1184
imports : [ MatRadioModule , FormsModule , ReactiveFormsModule , CommonModule ] ,
1136
1185
} )
1137
1186
class DisableableRadioButton {
1138
- @ViewChild ( MatRadioButton ) matRadioButton : MatRadioButton ;
1187
+ disabled = false ;
1188
+ disabledInteractive = false ;
1139
1189
1140
- set disabled ( value : boolean ) {
1141
- this . matRadioButton . disabled = value ;
1142
- }
1190
+ @ViewChild ( MatRadioButton ) matRadioButton : MatRadioButton ;
1143
1191
}
1144
1192
1145
1193
@Component ( {
0 commit comments