From b3a1a0f413313e341595f3a78ea6b02107202187 Mon Sep 17 00:00:00 2001 From: Christian Tellnes Date: Tue, 17 Oct 2023 08:40:11 +0200 Subject: [PATCH] fix(StepIndicator): react on changes to `is_current` data property (#2757) It looks like the StepIndicator does not react to changes in the `is_current` data property --- .../step-indicator/StepIndicatorContext.tsx | 2 +- .../__tests__/StepIndicator.test.tsx | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/dnb-eufemia/src/components/step-indicator/StepIndicatorContext.tsx b/packages/dnb-eufemia/src/components/step-indicator/StepIndicatorContext.tsx index b1ea7697487..89cc7a7647b 100644 --- a/packages/dnb-eufemia/src/components/step-indicator/StepIndicatorContext.tsx +++ b/packages/dnb-eufemia/src/components/step-indicator/StepIndicatorContext.tsx @@ -145,7 +145,7 @@ export function StepIndicatorProvider({ const currentStepFromProps = getActiveStepFromProps() if (currentStepFromProps !== activeStep) { - setActiveStep(props.current_step) + setActiveStep(currentStepFromProps) } }, [props.current_step, data]) diff --git a/packages/dnb-eufemia/src/components/step-indicator/__tests__/StepIndicator.test.tsx b/packages/dnb-eufemia/src/components/step-indicator/__tests__/StepIndicator.test.tsx index 8fcc083cc81..a4fb8a51731 100644 --- a/packages/dnb-eufemia/src/components/step-indicator/__tests__/StepIndicator.test.tsx +++ b/packages/dnb-eufemia/src/components/step-indicator/__tests__/StepIndicator.test.tsx @@ -414,6 +414,60 @@ describe('StepIndicator in loose mode', () => { ).toBeInTheDocument() }) + it('should react on is_current data prop change', () => { + const TestComp = (props) => { + return ( + <> + + + + ) + } + + const data1 = [ + { + title: 'Step A', + }, + { + title: 'Step B', + }, + { + title: 'Step C', + is_current: true, + }, + ] + + const { rerender } = render() + expect( + document.querySelector('li.dnb-step-indicator__item--current') + .textContent + ).toContain('3.Step CSteg 3 av 3') + + const data2 = [ + { + title: 'Step A', + }, + { + title: 'Step B', + is_current: true, + }, + { + title: 'Step C', + }, + ] + + rerender() + + expect( + document.querySelector('li.dnb-step-indicator__item--current') + .textContent + ).toContain('2.Step BSteg 2 av 3') + }) + it('should react on current_step prop change', () => { const TestComp = ({ id, ...props }) => { return (