File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,31 @@ describe('Radio Group Component', () => {
300300 expect ( first ( radios ) . checked ) . to . be . true ;
301301 expect ( group . value ) . to . equal ( first ( radios ) . value ) ;
302302 } ) ;
303+
304+ it ( 'form reset with multiple checked radios' , async ( ) => {
305+ form = await fixture ( html `
306+ < form >
307+ < igc-radio-group name ="fruit ">
308+ < igc-radio value ="apple " checked > Apple</ igc-radio >
309+ < igc-radio value ="banana " checked > Banana</ igc-radio >
310+ < igc-radio value ="orange " checked > Orange</ igc-radio >
311+ </ igc-radio-group >
312+ </ form >
313+ ` ) ;
314+ group = form . querySelector ( IgcRadioGroupComponent . tagName ) ! ;
315+ radios = Array . from ( form . querySelectorAll ( IgcRadioComponent . tagName ) ) ;
316+ setFormListener ( ) ;
317+
318+ expect ( first ( radios ) . checked ) . to . be . false ;
319+ expect ( last ( radios ) . checked ) . to . be . true ;
320+
321+ first ( radios ) . click ( ) ;
322+ expect ( first ( radios ) . checked ) . to . be . true ;
323+
324+ form . reset ( ) ;
325+ expect ( first ( radios ) . checked ) . to . be . false ;
326+ expect ( last ( radios ) . checked ) . to . be . true ;
327+ } ) ;
303328 } ) ;
304329
305330 describe ( 'Validation state' , ( ) => {
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ export default class IgcRadioComponent extends FormAssociatedRequiredMixin(
113113 }
114114
115115 protected override setDefaultValue ( ) : void {
116- this . _defaultValue = this === this . _checkedRadios [ 0 ] ;
116+ this . _defaultValue = this === last ( this . _checkedRadios ) ;
117117 }
118118
119119 /**
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export function getGroup(member: IgcRadioComponent) {
3939 const iterator = iterNodes < IgcRadioComponent > (
4040 globalThis . document . documentElement ,
4141 'SHOW_ELEMENT' ,
42- ( radio ) => radio . matches ( ` ${ member . tagName } [ name=' ${ member . name } ']` )
42+ ( radio ) => radio . matches ( member . tagName ) && radio . name === member . name
4343 ) ;
4444
4545 for ( const each of iterator ) {
You can’t perform that action at this time.
0 commit comments