diff --git a/packages/expandable-react/src/ExpandablePanel.tsx b/packages/expandable-react/src/ExpandablePanel.tsx index 452a129dfdd..f2bb225cc69 100644 --- a/packages/expandable-react/src/ExpandablePanel.tsx +++ b/packages/expandable-react/src/ExpandablePanel.tsx @@ -17,11 +17,14 @@ export const ExpandablePanel = Object.assign( as = "details", variant = "fill", open: controlledOpen, + defaultOpen, onOpenChange, ...rest } = props; - const [uncontrolledOpen, setUncontrolledOpen] = useState(false); + const [uncontrolledOpen, setUncontrolledOpen] = useState( + defaultOpen || false, + ); const [contentIsVisible, setContentIsVisible] = useState(false); const [expanderHeight, setExpanderHeight] = useState(0); diff --git a/packages/expandable-react/src/types.ts b/packages/expandable-react/src/types.ts index 39630095f13..f70f46178fe 100644 --- a/packages/expandable-react/src/types.ts +++ b/packages/expandable-react/src/types.ts @@ -10,6 +10,10 @@ export type ExpandablePanelProps = { variant?: "fill" | "stroke"; open?: boolean; + /* + * Initiell state av content. + */ + defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; } >; diff --git a/packages/jokul/src/components/expander/ExpandablePanel.tsx b/packages/jokul/src/components/expander/ExpandablePanel.tsx index 49b3529c9e8..7d9839b4ce6 100644 --- a/packages/jokul/src/components/expander/ExpandablePanel.tsx +++ b/packages/jokul/src/components/expander/ExpandablePanel.tsx @@ -17,11 +17,14 @@ export const ExpandablePanel = Object.assign( as = "details", variant = "fill", open: controlledOpen, + defaultOpen, onOpenChange, ...rest } = props; - const [uncontrolledOpen, setUncontrolledOpen] = useState(false); + const [uncontrolledOpen, setUncontrolledOpen] = useState( + defaultOpen || false, + ); const [contentIsVisible, setContentIsVisible] = useState(false); const [expanderHeight, setExpanderHeight] = useState(0); diff --git a/packages/jokul/src/components/expander/types.ts b/packages/jokul/src/components/expander/types.ts index 4984b9477ed..e8d34aca0cd 100644 --- a/packages/jokul/src/components/expander/types.ts +++ b/packages/jokul/src/components/expander/types.ts @@ -10,6 +10,10 @@ export type ExpandablePanelProps = { variant?: "fill" | "stroke"; open?: boolean; + /* + * Initiell state av content. + */ + defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; } >;