File tree Expand file tree Collapse file tree 4 files changed +27
-0
lines changed
Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 11[part = items ] {
22 display : flex;
33 flex-direction : column;
4+ gap : 0.25rem ;
45}
Original file line number Diff line number Diff line change @@ -23,6 +23,21 @@ export default class PgInputRadio extends HTMLElement {
2323 container : this . $items ,
2424 items : this . items ,
2525 type : ( ) => PgInputRadioItem ,
26+ create : ( $item : PgInputRadioItem ) => {
27+ $item . addEventListener ( 'change' , ( ) => {
28+ Array . from ( this . $items . children ) . forEach ( ( $ele : PgInputRadioItem ) => {
29+ if ( $ele === $item ) {
30+ $ele . checked = true ;
31+ } else {
32+ $ele . checked = false ;
33+ }
34+ } ) ;
35+ } ) ;
36+ }
2637 } ) ;
2738 }
39+
40+ get radios ( ) {
41+ return [ ...this . $items . children ] ;
42+ }
2843}
Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ label {
2323svg {
2424 width : 1.5rem ;
2525 height : 1.5rem ;
26+ margin-left : -0.5rem ;
2627}
Original file line number Diff line number Diff line change @@ -11,16 +11,26 @@ import style from './inputRadioItem.css';
1111export default class PgInputRadioItem extends HTMLElement {
1212 @Prop ( ) label : string = '' ;
1313 @Prop ( ) value : string = '' ;
14+ @Prop ( ) checked : boolean = false ;
1415
1516 @Part ( ) $input : HTMLInputElement ;
1617 @Part ( ) $label : HTMLSpanElement ;
1718
19+ connectedCallback ( ) {
20+ this . $input . addEventListener ( 'change' , ( ) => {
21+ this . dispatchEvent ( new CustomEvent ( 'change' ) ) ;
22+ } ) ;
23+ }
24+
1825 render ( changes ) {
1926 if ( changes . label ) {
2027 this . $label . textContent = this . label ;
2128 }
2229 if ( changes . value ) {
2330 this . $input . textContent = this . label ;
2431 }
32+ if ( changes . checked ) {
33+ this . $input . checked = this . checked ;
34+ }
2535 }
2636}
You can’t perform that action at this time.
0 commit comments