@@ -27,6 +27,11 @@ const Accordion: FC<IAccordionProps> = ({
27
27
const [ selectedItemId , setSelectedItemId ] = useState <
28
28
number | null | undefined
29
29
> ( selectedId ) ;
30
+
31
+ const [ selectedSectionId , setSelectedSectionId ] = useState <
32
+ number | null | undefined
33
+ > ( selectedId ) ;
34
+
30
35
const [ draggedId , setDraggedId ] = useState < number | null > ( null ) ;
31
36
const [ draggedOverId , setDraggedOverId ] = useState < number | null > ( null ) ;
32
37
const [ hoveredId , setHoveredId ] = useState < number | null > ( null ) ;
@@ -98,10 +103,18 @@ const Accordion: FC<IAccordionProps> = ({
98
103
role = 'presentation'
99
104
>
100
105
< h3
106
+ onClick = { ( ) => {
107
+ setSelectedSectionId ( section . id ) ;
108
+ } }
101
109
className = { classNames (
102
- "yl-relative yl-flex yl-cursor-pointer yl-select-none yl-items-center yl-font-semibold yl-capitalize yl-text-primary-text-color yl- p-4" ,
110
+ "yl-relative yl-flex yl-cursor-pointer yl-select-none yl-items-center yl-font-semibold yl-capitalize yl-p-4" ,
103
111
sectionTitleClassName ,
104
- { "yl-bg-primary-text-color/5" : expanded . includes ( section . id ) }
112
+ {
113
+ "yl-bg-primary-text-color/5" : expanded . includes ( section . id ) ,
114
+ "yl-text-primary-text-color" :
115
+ selectedSectionId !== section . id ,
116
+ "yl-text-primary" : selectedSectionId === section . id
117
+ }
105
118
) }
106
119
onKeyDown = { e =>
107
120
[ "Enter" , " " ] . includes ( e . key ) && toggleExpand ( section . id )
@@ -118,13 +131,21 @@ const Accordion: FC<IAccordionProps> = ({
118
131
< div className = 'yl-flex yl-flex-col yl-gap-1 yl-overflow-hidden yl-text-ellipsis yl-whitespace-nowrap yl-text-base' >
119
132
{ expanded . includes ( section . id ) ? (
120
133
< IconExpandLess
121
- onClick = { ( ) => toggleExpand ( section . id ) }
122
- className = 'yl-absolute yl-right-2 yl-w-6 yl-cursor-pointer yl-fill-primary-text-color hover:yl-fill-primary'
134
+ onClick = { e => {
135
+ e . stopPropagation ( ) ;
136
+ e . preventDefault ( ) ;
137
+ toggleExpand ( section . id ) ;
138
+ } }
139
+ className = 'yl-absolute yl-right-2 yl-w-6 yl-cursor-pointer yl-fill-primary hover:yl-fill-primary'
123
140
/>
124
141
) : (
125
142
< IconExpandMore
126
- onClick = { ( ) => toggleExpand ( section . id ) }
127
- className = 'yl-absolute yl-right-2 yl-w-6 yl-cursor-pointer yl-fill-primary-text-color hover:yl-fill-primary'
143
+ onClick = { e => {
144
+ e . stopPropagation ( ) ;
145
+ e . preventDefault ( ) ;
146
+ toggleExpand ( section . id ) ;
147
+ } }
148
+ className = 'yl-absolute yl-right-2 yl-w-6 yl-cursor-pointer yl-fill-primary hover:yl-fill-primary'
128
149
/>
129
150
) }
130
151
{ section . title }
@@ -168,6 +189,7 @@ const Accordion: FC<IAccordionProps> = ({
168
189
onSectionItemClick ?.( item ) ;
169
190
onSelected ?.( item ) ;
170
191
setSelectedItemId ( item . id ) ;
192
+ setSelectedSectionId ( section . id ) ;
171
193
} }
172
194
/>
173
195
) }
0 commit comments