File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,16 +86,22 @@ export const StepsProvider: React.FC<React.PropsWithChildren> = ({
8686 ) ;
8787} ;
8888
89+ export interface StepChangeContext {
90+ from : number ;
91+ to : number ;
92+ }
93+
8994export interface StepsProps {
9095 children : React . ReactNode ;
91- onStepChange ?: ( ) => void ;
96+ onStepChange ?: ( context ?: StepChangeContext ) => void ;
9297 startsFrom ?: number ;
9398}
9499
95100export const Steps : React . FC < StepsProps > = ( props ) => {
96101 const stepsContext = React . useContext ( StepsContext ) ;
97102 const { current, setCurrent, setSize } = stepsContext ;
98103 const [ isInitialRender , setIsInitialRender ] = React . useState ( true ) ;
104+ const prevStepRef = React . useRef ( current ) ;
99105
100106 React . useEffect ( ( ) => {
101107 setIsInitialRender ( false ) ;
@@ -109,6 +115,7 @@ export const Steps: React.FC<StepsProps> = (props) => {
109115 } else {
110116 setCurrent ( startsFrom ) ;
111117 }
118+ prevStepRef . current = startsFrom ;
112119 } , [ ] ) ;
113120
114121 React . useEffect ( ( ) => {
@@ -117,7 +124,10 @@ export const Steps: React.FC<StepsProps> = (props) => {
117124 } , [ props . children ] ) ;
118125
119126 React . useEffect ( ( ) => {
120- ! isInitialRender && props . onStepChange ?.( ) ;
127+ if ( ! isInitialRender ) {
128+ props . onStepChange ?.( { from : prevStepRef . current , to : current } ) ;
129+ }
130+ prevStepRef . current = current ;
121131 } , [ current ] ) ;
122132
123133 const steps = React . Children . map ( props . children , ( child , index ) => {
You can’t perform that action at this time.
0 commit comments