Skip to content

Commit

Permalink
Refactor Collapsible component to handle open state more efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
yigiterdev committed Feb 29, 2024
1 parent e4246cb commit eff03f6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/Collapsible/Collapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,22 @@ export const Collapsible = (props: CollapsibleProps) => {
label,
...rest
} = props

const [expanded, toggleExpanded] = useState(defaultOpen)
const isOpen = open ?? expanded

const handleOpenChange = (open: boolean) => {
toggleExpanded(open)
onOpenChange?.(open)
const handleSetExpanded = (isExpanded: boolean) => {
if (open !== undefined) {
return
}

toggleExpanded(isExpanded)
}

const handleOpenChange = (isOpen: boolean) => {
handleSetExpanded(isOpen)

onOpenChange?.(isOpen)
}

return (
Expand Down

0 comments on commit eff03f6

Please sign in to comment.