Skip to content

Commit 3362d6a

Browse files
committed
feat(ui): allow Wizard to take an initialStepId
The wizard now accepts an optional initialStepId prop. When passed, that becomes the active step on mount; when omitted, the existing "first registered step becomes default" behavior is preserved. This is the hook the host needs to land server-derived initial step logic later — e.g., ConfigureSSO computing the initial step from the user's enterprise connection state. Hosts that don't pass it work unchanged.
1 parent 1c4bbdc commit 3362d6a

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

  • packages/ui/src/components/ConfigureSSO/elements/Wizard

packages/ui/src/components/ConfigureSSO/elements/Wizard/Wizard.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ import { useWizard, WizardContext } from './WizardContext';
55

66
interface RootProps {
77
children: React.ReactNode;
8+
/**
9+
* Initial active step id. When provided, the wizard mounts with this
10+
* step active. When omitted, the first registered step becomes the
11+
* default — useful when steps are statically known and order is the
12+
* source of truth, or when the host derives the initial step from
13+
* external state (e.g., a server-state hook) and passes it down.
14+
*/
15+
initialStepId?: string;
816
}
917

10-
const Root = ({ children }: RootProps): JSX.Element => {
18+
const Root = ({ children, initialStepId }: RootProps): JSX.Element => {
1119
const parentWizard = React.useContext(WizardContext);
1220
const isNested = parentWizard !== null;
1321

1422
return (
1523
<RootInner
1624
parentWizard={parentWizard}
1725
isNested={isNested}
26+
initialStepId={initialStepId}
1827
>
1928
{children}
2029
</RootInner>
@@ -24,15 +33,17 @@ const Root = ({ children }: RootProps): JSX.Element => {
2433
interface RootInnerProps {
2534
parentWizard: WizardContextValue | null;
2635
isNested: boolean;
36+
initialStepId?: string;
2737
children: React.ReactNode;
2838
}
2939

30-
const RootInner = ({ parentWizard, isNested, children }: RootInnerProps): JSX.Element => {
40+
const RootInner = ({ parentWizard, isNested, initialStepId, children }: RootInnerProps): JSX.Element => {
3141
// Stable registry of mounted Steps. Insertion order = JSX order =
3242
// display order
3343
const [activeSteps, setActiveSteps] = React.useState<WizardActiveStep[]>([]);
34-
// Active step id. Defaults to the first registered step's id
35-
const [currentStepId, setCurrentStepId] = React.useState<string | undefined>(undefined);
44+
// Active step id. Defaults to the first registered step's id when
45+
// `initialStepId` is omitted; otherwise mounts with the explicit id.
46+
const [currentStepId, setCurrentStepId] = React.useState<string | undefined>(initialStepId);
3647

3748
const registerStep = React.useCallback((step: WizardActiveStep) => {
3849
setActiveSteps(prev => {
@@ -171,6 +182,11 @@ Step.displayName = 'Wizard.Step';
171182
* are provided by the host layout via `useWizard()`. Each step owns
172183
* its own footer via `<Step.Footer>`, which reads the nearest wizard
173184
* via `useWizard()` so nested-wizard fall-through works automatically.
185+
*
186+
* When mounted without `initialStepId`, the wizard defaults to the
187+
* first registered step. When `initialStepId` is provided, the wizard
188+
* starts on that step instead — useful for resuming a flow from
189+
* server-derived state.
174190
*/
175191
export const Wizard = Object.assign(Root, {
176192
Step,

0 commit comments

Comments
 (0)