@@ -10,14 +10,22 @@ export interface CCollapseProps extends HTMLAttributes<HTMLDivElement> {
1010 * A string of all className you want applied to the base component.
1111 */
1212 className ?: string
13+ /**
14+ * Callback fired when the component requests to be hidden.
15+ */
16+ onHide ?: ( ) => void
17+ /**
18+ * Callback fired when the component requests to be shown.
19+ */
20+ onShow ?: ( ) => void
1321 /**
1422 * Toggle the visibility of component.
1523 */
1624 visible ?: boolean
1725}
1826
1927export const CCollapse = forwardRef < HTMLDivElement , CCollapseProps > (
20- ( { children, className, visible, ...rest } , ref ) => {
28+ ( { children, className, onHide , onShow , visible, ...rest } , ref ) => {
2129 const [ height , setHeight ] = useState < number > ( )
2230 const collapseRef = useRef < HTMLDivElement > ( null )
2331 const forkedRef = useForkedRef ( ref , collapseRef )
@@ -33,6 +41,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
3341 }
3442
3543 const onEntering = ( ) => {
44+ onShow && onShow ( )
3645 collapseRef . current && setHeight ( collapseRef . current . scrollHeight )
3746 }
3847
@@ -45,6 +54,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
4554 }
4655
4756 const onExiting = ( ) => {
57+ onHide && onHide ( )
4858 setHeight ( 0 )
4959 }
5060
@@ -86,6 +96,8 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
8696CCollapse . propTypes = {
8797 children : PropTypes . node ,
8898 className : PropTypes . string ,
99+ onHide : PropTypes . func ,
100+ onShow : PropTypes . func ,
89101 visible : PropTypes . bool ,
90102}
91103
0 commit comments