@@ -205,6 +205,8 @@ class Utils {
205
205
labelToRestore = labelSibling . cloneNode ( true ) ;
206
206
// Prefer the explicitly set title, fall back to text from the label.
207
207
title = title || labelSibling . textContent ;
208
+ // Remove the original label
209
+ labelSibling . parentNode . removeChild ( labelSibling ) ;
208
210
}
209
211
}
210
212
return { title, remainLabel, randomID, labelToRestore } ;
@@ -226,6 +228,8 @@ class Utils {
226
228
if ( labelNode . parentNode ) {
227
229
labelNode . parentNode . insertBefore ( cloneEle , labelNode ) ;
228
230
}
231
+ // Replace the original element with the new one
232
+ ele . parentNode . replaceChild ( templateNode . firstElementChild || templateNode , ele ) ;
229
233
return { cloneEle, templateNode, labelNode } ;
230
234
}
231
235
static insertRadioboxTitle ( title , bindLabel , labelNode , cloneEle ) {
@@ -327,7 +331,7 @@ styleInject(css_248z);
327
331
328
332
class RadioBox {
329
333
static instances = [ ] ;
330
- static version = '2.0.1 ' ;
334
+ static version = '2.0.2 ' ;
331
335
static firstLoad = true ;
332
336
element = null ;
333
337
options ;
@@ -393,18 +397,13 @@ class RadioBox {
393
397
let bindLabel = this . options . bindLabel ?? false ;
394
398
let { title, remainLabel, randomID, labelToRestore } = Utils . handleRadioboxTitle ( ele , labelSibling ) ;
395
399
bindLabel = remainLabel ? true : bindLabel ;
396
- if ( title && labelSibling && labelSibling . tagName === 'LABEL' ) {
397
- title = labelSibling . textContent || title ;
398
- labelSibling . parentNode ?. removeChild ( labelSibling ) ;
399
- }
400
400
// Handle radiobox checked status
401
401
if ( this . options . checked ) {
402
402
// Initialize radiobox checked status based on options
403
403
this . updateRadioboxCheckedStatus ( ele , index ) ;
404
404
}
405
405
// Insert radiobox
406
- let { cloneEle, templateNode, labelNode } = Utils . insertRadiobox ( this . id . toString ( ) , ele , randomID , remainLabel ) ;
407
- ele . parentNode ?. replaceChild ( templateNode . firstElementChild || templateNode , ele ) ;
406
+ let { cloneEle, labelNode } = Utils . insertRadiobox ( this . id . toString ( ) , ele , randomID , remainLabel ) ;
408
407
// Insert radiobox title
409
408
Utils . insertRadioboxTitle ( title , bindLabel , labelNode , cloneEle ) ;
410
409
// Add event listener
@@ -460,6 +459,21 @@ class RadioBox {
460
459
set onChange ( callback ) {
461
460
this . onChangeCallback = callback ;
462
461
}
462
+ /**
463
+ * Get all radio box elements
464
+ * @return {RadioInputElement[] } All radio box elements
465
+ */
466
+ get elements ( ) {
467
+ return this . allElement ;
468
+ }
469
+ /**
470
+ * Get value of the checked radio box
471
+ * @return {string } Value of the checked radio box
472
+ */
473
+ get value ( ) {
474
+ let checkedRadio = this . allElement . find ( element => element . checked ) ;
475
+ return checkedRadio ? checkedRadio . value : null ;
476
+ }
463
477
empty ( ) {
464
478
this . allElement . forEach ( element => {
465
479
element . checked = false ;
@@ -481,14 +495,6 @@ class RadioBox {
481
495
instance . destroy ( ) ;
482
496
}
483
497
}
484
- /**
485
- * Get value of the checked radio box
486
- * @return {string } Value of the checked radio box
487
- */
488
- get value ( ) {
489
- let checkedRadio = this . allElement . find ( element => element . checked ) ;
490
- return checkedRadio ? checkedRadio . value : null ;
491
- }
492
498
}
493
499
494
500
export { RadioBox as default } ;
0 commit comments