Skip to content

Commit

Permalink
update hack
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoskolodny committed Oct 4, 2023
1 parent 83bb0bf commit 56c8fa3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/__screenshot_tests__/progress-bar-screenshot-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {openStoryPage, screen} from '../test-utils';
const COLORS = ['default', 'red'];

test.each(COLORS)('ProgressBar - color={%s}', async (color) => {
await openStoryPage({id: 'components-progressbar--default', args: {color}});
await openStoryPage({id: 'components-progress-bar--progress-bar-story', args: {color}});

const stepper = await screen.findByTestId('progress-bar');

Expand Down
13 changes: 4 additions & 9 deletions src/progress-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ export const ProgressBarStepped: React.FC<ProgressBarSteppedProps> = ({
const [step, setStep] = React.useState(reverse ? steps : 0);
const [isAnimating, setIsAnimating] = React.useState(false);

/** If reverse value changed, we reset the initial state of all the progress bars */
const reverseValue = React.useRef(reverse);
/** If reverse or steps value changed, we reset the initial state of all the progress bars */
React.useEffect(() => {
const initialStep = reverse ? steps : 0;
if (reverseValue.current !== reverse) {
reverseValue.current = reverse;
setStep(initialStep);
}
setStep(reverse ? steps : 0);
}, [reverse, steps]);

React.useEffect(() => {
Expand Down Expand Up @@ -108,8 +103,8 @@ export const ProgressBarStepped: React.FC<ProgressBarSteppedProps> = ({
{Array.from({length: steps}, (_, idx) => {
return (
<ProgressBar
// this key allows to reset all the progress bars if reverse value changed
key={String(idx) + String(reverseValue.current)}
// this key allows to reset all the progress bars if reverse or steps values changed
key={String(idx) + String(reverse) + String(steps)}
progressPercent={idx < step ? 100 : 0}
color={color}
reverse={reverse}
Expand Down

0 comments on commit 56c8fa3

Please sign in to comment.