1
- import { LitElement , html , nothing } from " lit" ;
2
- import { property , queryAssignedElements } from " lit/decorators.js" ;
3
- import { Radio } from " ../radio/radio" ;
1
+ import { LitElement , html , nothing } from ' lit' ;
2
+ import { property , queryAssignedElements } from ' lit/decorators.js' ;
3
+ import { Radio } from ' ../radio/radio' ;
4
4
5
5
export class RadioGroup extends LitElement {
6
- @property ( { reflect : true } ) direction : "horizontal" | "vertical" = "vertical" ;
7
- @property ( { reflect : true } ) value = "" ;
6
+ @property ( { reflect : true } ) direction : 'horizontal' | 'vertical' =
7
+ 'vertical' ;
8
+ @property ( { reflect : true } ) value = '' ;
8
9
9
10
@queryAssignedElements ( ) private radios ! : Radio [ ] ;
10
11
11
12
connectedCallback ( ) {
12
13
super . connectedCallback ( ) ;
13
- this . addEventListener (
14
- "radio-input-change" ,
15
- this . handleRadioChangeClick
16
- ) ;
14
+ this . addEventListener ( 'radio-input-change' , this . handleRadioChangeClick ) ;
17
15
}
18
16
19
- private selectDefaultOption ( ) {
20
- if ( ! this . value ) return ;
21
- const selectedRadio = this . radios . find ( radio => radio . value == this . value ) ;
22
- if ( ! selectedRadio ) return
17
+ private selectDefaultOption ( ) {
18
+ if ( ! this . value ) return ;
19
+ const selectedRadio = this . radios . find (
20
+ ( radio ) => radio . value == this . value ,
21
+ ) ;
22
+ if ( ! selectedRadio ) return ;
23
23
selectedRadio . checked = true ;
24
24
}
25
25
26
26
private handleRadioChangeClick ( e : Event ) {
27
27
const index = this . radios . indexOf ( e . target as Radio ) ;
28
28
const selectedRadio = this . radios [ index ] ;
29
29
30
- if ( ! selectedRadio || selectedRadio . checked || selectedRadio . disabled ) return ;
30
+ if ( ! selectedRadio || selectedRadio . checked || selectedRadio . disabled )
31
+ return ;
31
32
32
33
selectedRadio . checked = true ;
33
34
@@ -38,14 +39,14 @@ export class RadioGroup extends LitElement {
38
39
} ) ;
39
40
40
41
this . dispatchEvent (
41
- new CustomEvent ( " radio-group-change" , {
42
+ new CustomEvent ( ' radio-group-change' , {
42
43
detail : {
43
44
checked : selectedRadio ,
44
45
index,
45
46
} ,
46
47
bubbles : true ,
47
48
composed : true ,
48
- } )
49
+ } ) ,
49
50
) ;
50
51
}
51
52
0 commit comments