MCPcopy Create free account
hub / github.com/adobe/react-spectrum / WizardInner

Function WizardInner

packages/react-aria-components/src/Wizard.tsx:373–463  ·  view source on GitHub ↗
({props, collection, tabsRef}: WizardInnerProps)

Source from the content-addressed store, hash-verified

371}
372
373function WizardInner({props, collection, tabsRef}: WizardInnerProps) {
374 let {
375 className,
376 selectedKey,
377 defaultSelectedKey,
378 onSelectionChange,
379 completedKeys,
380 allowsSelectingIncompleteSteps,
381 disabledKeys,
382 ...tabsProps
383 } = props;
384
385 let state = useWizardState({
386 collection,
387 selectedKey,
388 defaultSelectedKey,
389 onSelectionChange,
390 completedKeys,
391 allowsSelectingIncompleteSteps,
392 disabledKeys
393 });
394
395 let {previousKey, nextKey} = state;
396
397 // Like Calendar, if the previous or next button becomes disabled while it's focused, e.g. on the
398 // first or last step, focus moves to the current step (see useWizardStep).
399 let [previousFocused, setPreviousFocused] = useState(false);
400 let previousDisabled = props.isDisabled || previousKey == null;
401 if (previousDisabled && previousFocused) {
402 setPreviousFocused(false);
403 state.setFocused(true);
404 }
405
406 let [nextFocused, setNextFocused] = useState(false);
407 let nextDisabled = props.isDisabled || nextKey == null;
408 if (nextDisabled && nextFocused) {
409 setNextFocused(false);
410 state.setFocused(true);
411 }
412
413 // Buttons with the previous and next slots move to the previous and next steps, and are disabled
414 // when there isn't one. The slots of an outer ButtonContext, such as the close slot of a Dialog,
415 // are kept so that their buttons still work within the wizard.
416 let buttonContext = useContext(ButtonContext);
417 let outerButtonSlots =
418 buttonContext && 'slots' in buttonContext ? buttonContext.slots : undefined;
419 let buttonSlots = {
420 [DEFAULT_SLOT]: {},
421 ...outerButtonSlots,
422 previous: {
423 isDisabled: previousDisabled,
424 onPress: () => {
425 if (previousKey != null) {
426 state.setSelectedKey(previousKey);
427 }
428 },
429 onFocusChange: setPreviousFocused
430 },

Callers

nothing calls this directly

Calls 4

useWizardStateFunction · 0.85
withDefaultClassNameFunction · 0.85
setFocusedMethod · 0.65
setSelectedKeyMethod · 0.65

Tested by

no test coverage detected