Skip to content

Commit fba968a

Browse files
committed
fix: wizard goToStep boundary
1 parent 4b5e9de commit fba968a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/wizard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const Wizard: React.FC<WizardProps> = React.memo(
3030

3131
const goToStep = React.useRef((stepIndex: number) => {
3232
if (
33-
stepIndex > 0 &&
33+
stepIndex >= 0 &&
3434
stepIndex < React.Children.toArray(children).length
3535
) {
3636
setActiveStep(stepIndex);

test/useWizard.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ describe('useWizard', () => {
122122
expect(result.current.isLastStep).toBe(true);
123123
});
124124

125+
test('should go to given step index', async () => {
126+
const { result } = renderUseWizardHook(1);
127+
128+
act(() => {
129+
result.current.goToStep(0);
130+
});
131+
132+
expect(result.current.activeStep).toBe(0);
133+
expect(result.current.isFirstStep).toBe(true);
134+
expect(result.current.isLastStep).toBe(false);
135+
});
136+
125137
test('should go to given step index and not invoke `handleStep` handler', async () => {
126138
const handler = jest.fn();
127139
const { result } = renderUseWizardHook();

0 commit comments

Comments
 (0)