@@ -453,6 +453,45 @@ describe('RadioGroup', () => {
453
453
expect ( group ) . not . toHaveAttribute ( 'data-invalid' ) ;
454
454
} ) ;
455
455
456
+ it ( 'supports validation errors when last radio is disabled' , async ( ) => {
457
+ let { getByRole, getAllByRole, getByTestId} = render (
458
+ < form data-testid = "form" >
459
+ < RadioGroup isRequired >
460
+ < Label > Test</ Label >
461
+ < Radio value = "a" > A</ Radio >
462
+ < Radio value = "b" isDisabled > B</ Radio >
463
+ < FieldError />
464
+ </ RadioGroup >
465
+ </ form >
466
+ ) ;
467
+
468
+ let group = getByRole ( 'radiogroup' ) ;
469
+ expect ( group ) . not . toHaveAttribute ( 'aria-describedby' ) ;
470
+ expect ( group ) . not . toHaveAttribute ( 'data-invalid' ) ;
471
+
472
+ let radios = getAllByRole ( 'radio' ) ;
473
+ for ( let input of radios ) {
474
+ expect ( input ) . toHaveAttribute ( 'required' ) ;
475
+ expect ( input ) . not . toHaveAttribute ( 'aria-required' ) ;
476
+ expect ( input . validity . valid ) . toBe ( false ) ;
477
+ }
478
+
479
+ act ( ( ) => { getByTestId ( 'form' ) . checkValidity ( ) ; } ) ;
480
+
481
+ expect ( group ) . toHaveAttribute ( 'aria-describedby' ) ;
482
+ expect ( document . getElementById ( group . getAttribute ( 'aria-describedby' ) ) ) . toHaveTextContent ( 'Constraints not satisfied' ) ;
483
+ expect ( group ) . toHaveAttribute ( 'data-invalid' ) ;
484
+ expect ( document . activeElement ) . toBe ( radios [ 0 ] ) ;
485
+
486
+ await user . click ( radios [ 0 ] ) ;
487
+ for ( let input of radios ) {
488
+ expect ( input . validity . valid ) . toBe ( true ) ;
489
+ }
490
+
491
+ expect ( group ) . not . toHaveAttribute ( 'aria-describedby' ) ;
492
+ expect ( group ) . not . toHaveAttribute ( 'data-invalid' ) ;
493
+ } ) ;
494
+
456
495
it ( 'should support focus events' , async ( ) => {
457
496
let onBlur = jest . fn ( ) ;
458
497
let onFocus = jest . fn ( ) ;
0 commit comments