@@ -10,14 +10,22 @@ export interface CCollapseProps extends HTMLAttributes<HTMLDivElement> {
10
10
* A string of all className you want applied to the base component.
11
11
*/
12
12
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
13
21
/**
14
22
* Toggle the visibility of component.
15
23
*/
16
24
visible ?: boolean
17
25
}
18
26
19
27
export const CCollapse = forwardRef < HTMLDivElement , CCollapseProps > (
20
- ( { children, className, visible, ...rest } , ref ) => {
28
+ ( { children, className, onHide , onShow , visible, ...rest } , ref ) => {
21
29
const [ height , setHeight ] = useState < number > ( )
22
30
const collapseRef = useRef < HTMLDivElement > ( null )
23
31
const forkedRef = useForkedRef ( ref , collapseRef )
@@ -33,6 +41,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
33
41
}
34
42
35
43
const onEntering = ( ) => {
44
+ onShow && onShow ( )
36
45
collapseRef . current && setHeight ( collapseRef . current . scrollHeight )
37
46
}
38
47
@@ -45,6 +54,7 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
45
54
}
46
55
47
56
const onExiting = ( ) => {
57
+ onHide && onHide ( )
48
58
setHeight ( 0 )
49
59
}
50
60
@@ -86,6 +96,8 @@ export const CCollapse = forwardRef<HTMLDivElement, CCollapseProps>(
86
96
CCollapse . propTypes = {
87
97
children : PropTypes . node ,
88
98
className : PropTypes . string ,
99
+ onHide : PropTypes . func ,
100
+ onShow : PropTypes . func ,
89
101
visible : PropTypes . bool ,
90
102
}
91
103
0 commit comments