Skip to content

Commit 6ba38fd

Browse files
committed
make sure stepCount doesn't count false / null or undefined child items
1 parent d28bd99 commit 6ba38fd

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/wizard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Wizard: React.FC<WizardProps> = React.memo(
1111
const hasNextStep = React.useRef(true);
1212
const hasPreviousStep = React.useRef(false);
1313
const nextStepHandler = React.useRef<Handler>(() => {});
14-
const stepCount = React.Children.count(children);
14+
const stepCount = React.Children.toArray(children).length;
1515

1616
hasNextStep.current = activeStep < stepCount - 1;
1717
hasPreviousStep.current = activeStep > 0;

test/useWizard.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const renderUseWizardHook = (initialStartIndex = 0) => {
1212
wrapper: ({ children, startIndex }) => (
1313
<Wizard startIndex={startIndex}>
1414
<p>step 1 {children}</p>
15+
{false && <p>Optional step</p>}
1516
<p>step 2 {children}</p>
1617
</Wizard>
1718
),

0 commit comments

Comments
 (0)