From 1c4f94464c2cc6c3cc818209d3bfab8b3050ea10 Mon Sep 17 00:00:00 2001 From: Elliot Spall <132617474+PuppetFoam@users.noreply.github.com> Date: Fri, 5 Jul 2024 07:43:37 -0400 Subject: [PATCH] Fix: #6820 updating activeStep does not actually change the active step (#6841) * useeffect for active step * switched to use updateActiveStep and check for valid index --- components/lib/stepper/Stepper.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/lib/stepper/Stepper.js b/components/lib/stepper/Stepper.js index 430b46e7a1..e169cbc9c0 100644 --- a/components/lib/stepper/Stepper.js +++ b/components/lib/stepper/Stepper.js @@ -2,7 +2,7 @@ import React from 'react'; import { PrimeReactContext } from '../api/Api'; import { useHandleStyle } from '../componentbase/ComponentBase'; import { CSSTransition } from '../csstransition/CSSTransition'; -import { useMergeProps, useMountEffect } from '../hooks/Hooks'; +import { useMergeProps, useMountEffect, useUpdateEffect } from '../hooks/Hooks'; import { UniqueComponentId, classNames } from '../utils/Utils'; import { StepperBase } from './StepperBase'; import { StepperContent } from './StepperContent'; @@ -29,6 +29,12 @@ export const Stepper = React.memo( } }); + useUpdateEffect(() => { + if (props.activeStep >= 0 && props.activeStep <= stepperPanels().length - 1) { + updateActiveStep(undefined, props.activeStep); + } + }, [props.activeStep]); + const getStepProp = (step, name) => { return step?.props?.[name]; };