@@ -14,7 +14,7 @@ const Label = styled.label`
1414 cursor: pointer;
1515`
1616
17- const Checkbox = styled . input `
17+ const Radio = styled . input `
1818 outline: 2px;
1919 clip: unset;
2020 position: relative;
@@ -26,22 +26,32 @@ const Checkbox = styled.input`
2626
2727const FilterIsland = ( { originalSelect, selectOptions} ) => {
2828
29- const onChange = ( event ) => {
29+ const onChange = ( parentValue : string , event ) => {
30+ let parent = null
3031 for ( let i = 0 ; i < originalSelect . options . length ; i ++ ) {
31- if ( event . target . value === originalSelect . options [ i ] . value ) {
32- originalSelect . options [ i ] . selected = event . target . checked
32+ if ( ! selectOptions . find ( opt => opt . value === originalSelect . options [ i ] . value ) . label . startsWith ( '-' ) ) {
33+ parent = originalSelect . options [ i ] . value
34+ continue
3335 }
36+
37+ if ( parentValue !== parent ) continue
38+ originalSelect . options [ i ] . selected = event . target . value === originalSelect . options [ i ] . value
3439 }
3540 originalSelect ?. closest ( 'form' ) . querySelector ( '[data-bef-auto-submit-click]' ) ?. click ( ) ;
3641 } ;
3742
38- const optionSets : Array < { label : string , options : { label : string , value : string } [ ] } > = [ ]
43+
44+ const optionSets : Array < {
45+ label : string ,
46+ value : string ,
47+ options : { label : string , value : string } [ ]
48+ } > = [ ]
3949 let parentLabel = ''
4050
4151 selectOptions . map ( option => {
4252 if ( ! option . label . startsWith ( '-' ) ) {
4353 parentLabel = option . label
44- optionSets . push ( { label : option . label , options : [ ] } )
54+ optionSets . push ( { ... option , options : [ ] } )
4555 } else {
4656 optionSets . find ( item => item . label === parentLabel ) ?. options . push ( {
4757 value : option . value ,
@@ -51,26 +61,38 @@ const FilterIsland = ({originalSelect, selectOptions}) => {
5161 } )
5262
5363
54- let defaultValues :Array < string > = [ ] ;
64+ let defaultValues : Array < string > = [ ] ;
5565 for ( let option of originalSelect . children ) {
5666 if ( option . getAttribute ( 'selected' ) ) defaultValues . push ( option . getAttribute ( 'value' ) )
5767 }
5868
5969 return (
6070 < div className = "hierarchy-preact-checkbox" >
61- { optionSets . map ( ( set , i ) =>
62- < Fieldset key = { i } className = "preact-checkbox-item" >
71+ { optionSets . map ( set =>
72+ < Fieldset key = { set . value } className = "preact-checkbox-item" >
6373 < legend >
6474 { set . label }
6575 </ legend >
6676
77+ < Label >
78+ < Radio
79+ type = "radio"
80+ name = { set . value }
81+ defaultChecked = { ! set . options . find ( option => defaultValues . includes ( option . value ) ) }
82+ onChange = { onChange . bind ( null , set . value ) }
83+ data-bef-auto-submit-exclude
84+ />
85+ - All -
86+ </ Label >
87+
6788 { set . options . map ( option =>
6889 < Label key = { option . value } >
69- < Checkbox
70- type = "checkbox"
90+ < Radio
91+ type = "radio"
92+ name = { set . value }
7193 value = { option . value }
7294 defaultChecked = { defaultValues . includes ( option . value ) }
73- onChange = { onChange }
95+ onChange = { onChange . bind ( null , set . value ) }
7496 data-bef-auto-submit-exclude
7597 />
7698 { option . label }
0 commit comments