@@ -44,6 +44,13 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
4444 setInternalOptions ( options )
4545 } , [ options ] )
4646
47+ function handleOpenChange ( open : boolean ) {
48+ if ( ! open ) {
49+ setInternalOptions ( options )
50+ }
51+ setOpenModal ( open )
52+ }
53+
4754 function toggleItem ( column : string , label : string ) {
4855 setInternalOptions ( ( prev ) => {
4956 const prevOptions = prev [ column ]
@@ -73,8 +80,8 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
7380 setOpenModal ( false )
7481 }
7582
76- function columnCount ( column : string ) {
77- return internalOptions [ column ] ?. length || 0
83+ function columnSelectedCount ( column : string ) {
84+ return internalOptions [ column ] ?. filter ( ( o ) => o . isSelected ) . length || 0
7885 }
7986
8087 const columns = Object . keys ( internalOptions )
@@ -84,7 +91,7 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
8491 )
8592
8693 return (
87- < Popover open = { openModal } onOpenChange = { setOpenModal } >
94+ < Popover open = { openModal } onOpenChange = { handleOpenChange } >
8895 < PopoverTrigger asChild >
8996 < Button variant = "outline" className = { cn ( 'w-fit' , classNames ?. trigger ) } >
9097 < Typography className = "text-icon-tertiary" > Filter</ Typography >
@@ -114,7 +121,7 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
114121 < Typography weight = "normal" type = "body" >
115122 { column }
116123 </ Typography >
117- < CountBadge count = { columnCount ( column ) } />
124+ < CountBadge count = { columnSelectedCount ( column ) } />
118125 </ li >
119126 ) ) }
120127 </ ul >
@@ -164,7 +171,7 @@ function CountBadge({ count }: { count: number }) {
164171 return (
165172 < div
166173 className = { cn (
167- 'size-[22px] rounded-full bg-surface-primary border flex items-center justify-center' ,
174+ 'size-[22px] rounded-full bg-surface-primary border flex items-center justify-center text-xs ' ,
168175 {
169176 'opacity-0' : count === 0 ,
170177 }
0 commit comments