Skip to content

Commit 3e778c0

Browse files
committed
adds findChildren
1 parent 326ae5c commit 3e778c0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

packages/wizard/src/Wizard/Wizard.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Children, isValidElement } from 'react';
22

33
import { Direction } from '@leafygreen-ui/descendants';
4-
import { findChild } from '@leafygreen-ui/lib';
4+
import { findChild, findChildren } from '@leafygreen-ui/lib';
55

66
import { useWizardControlledValue } from '../utils/useWizardControlledValue/useWizardControlledValue';
77
import { WizardContext } from '../WizardContext/WizardContext';
@@ -24,14 +24,11 @@ export function Wizard({
2424
setValue: setActiveStep,
2525
} = useWizardControlledValue<number>(activeStepProp, undefined, 0);
2626

27-
const stepChildren = Children.toArray(children).filter(child => {
28-
if (isValidElement(child)) {
29-
const displayName = (child.type as any)?.displayName;
30-
return displayName && displayName.includes('Step');
31-
}
32-
33-
return false;
34-
});
27+
const stepChildren = findChildren(
28+
children,
29+
WizardSubComponentProperties.Step,
30+
);
31+
const footerChild = findChild(children, WizardSubComponentProperties.Footer);
3532

3633
const updateStep = (direction: Direction) => {
3734
const getNextStep = (curr: number) => {
@@ -50,8 +47,6 @@ export function Wizard({
5047
onStepChange?.(getNextStep(activeStep));
5148
};
5249

53-
const footerChild = findChild(children, WizardSubComponentProperties.Footer);
54-
5550
// Get the current step to render
5651
const currentStep = stepChildren[activeStep] || null;
5752

@@ -64,7 +59,6 @@ export function Wizard({
6459
>
6560
<div className={wizardContainerStyles}>
6661
<div className={stepContentStyles}>{currentStep}</div>
67-
{/* Render footer */}
6862
{footerChild}
6963
</div>
7064
</WizardContext.Provider>

0 commit comments

Comments
 (0)