@@ -7,7 +7,7 @@ import { mdiChevronDown, mdiChevronUp } from '@lumx/icons';
77import isEmpty from 'lodash/isEmpty' ;
88
99import { ColorPalette , DragHandle , Emphasis , IconButton , IconButtonProps , Theme } from '@lumx/react' ;
10- import { GenericProps , HasTheme , isComponent } from '@lumx/react/utils/type' ;
10+ import { GenericProps , HasCloseMode , HasTheme , isComponent } from '@lumx/react/utils/type' ;
1111import { getRootClassName , handleBasicClasses } from '@lumx/react/utils/className' ;
1212import { partitionMulti } from '@lumx/react/utils/partitionMulti' ;
1313import { useTheme } from '@lumx/react/utils/theme/ThemeContext' ;
@@ -17,7 +17,7 @@ import { IS_BROWSER } from '@lumx/react/constants';
1717/**
1818 * Defines the props of the component.
1919 */
20- export interface ExpansionPanelProps extends GenericProps , HasTheme {
20+ export interface ExpansionPanelProps extends GenericProps , HasCloseMode , HasTheme {
2121 /** Whether the expansion panel has a background. */
2222 hasBackground ?: boolean ;
2323 /** Whether the header has a divider. */
@@ -52,7 +52,9 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
5252/**
5353 * Component default props.
5454 */
55- const DEFAULT_PROPS : Partial < ExpansionPanelProps > = { } ;
55+ const DEFAULT_PROPS : Partial < ExpansionPanelProps > = {
56+ closeMode : 'unmount' ,
57+ } ;
5658
5759const isDragHandle = isComponent ( DragHandle ) ;
5860const isHeader = isComponent ( 'header' ) ;
@@ -69,6 +71,7 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
6971 const defaultTheme = useTheme ( ) || Theme . light ;
7072 const {
7173 className,
74+ closeMode = DEFAULT_PROPS . closeMode ,
7275 children : anyChildren ,
7376 hasBackground,
7477 hasHeaderDivider,
@@ -127,32 +130,32 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
127130
128131 const wrapperRef = useRef < HTMLDivElement > ( null ) ;
129132
130- // Children visible while the open/close transition is running
133+ // Children stay visible while the open/close transition is running
131134 const [ isChildrenVisible , setChildrenVisible ] = React . useState ( isOpen ) ;
132135
133136 const isOpenRef = React . useRef ( isOpen ) ;
134137 React . useEffect ( ( ) => {
135- if ( isOpen ) {
138+ if ( isOpen || closeMode === 'hide' ) {
136139 setChildrenVisible ( true ) ;
137140 } else if ( ! IS_BROWSER ) {
138141 // Outside a browser we can't wait for the transition
139142 setChildrenVisible ( false ) ;
140143 }
141144 isOpenRef . current = isOpen ;
142- } , [ isOpen ] ) ;
145+ } , [ closeMode , isOpen ] ) ;
143146
144- // Change children visibility on transition end
147+ // Change children's visibility on the transition end
145148 React . useEffect ( ( ) => {
146149 const { current : wrapper } = wrapperRef ;
147150 if ( ! IS_BROWSER || ! wrapper ) {
148151 return undefined ;
149152 }
150153 const onTransitionEnd = ( ) => {
151- setChildrenVisible ( isOpenRef . current ) ;
154+ setChildrenVisible ( isOpenRef . current || closeMode === 'hide' ) ;
152155 } ;
153156 wrapper . addEventListener ( 'transitionend' , onTransitionEnd ) ;
154157 return ( ) => wrapper . removeEventListener ( 'transitionend' , onTransitionEnd ) ;
155- } , [ ] ) ;
158+ } , [ closeMode ] ) ;
156159
157160 return (
158161 < section ref = { ref } { ...forwardedProps } className = { rootClassName } >
0 commit comments