Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/components/steps/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,24 @@ const Steps = forwardRefWithStatics(

const stepItemList = useMemo<React.ReactNode[]>(() => {
if (options) {
const optionsDisplayList = sequence === 'reverse' ? options.reverse() : options;
return options.map<React.ReactNode>((item, index) => {
const stepIndex = sequence === 'reverse' ? optionsDisplayList.length - index - 1 : index;
return <StepItem key={index} {...item} index={stepIndex} status={handleStatus(item, index)} />;
const displayList = sequence === 'reverse' ? [...options].reverse() : options;
return displayList.map<React.ReactNode>((item, index) => {
const originalIndex = sequence === 'reverse' ? displayList.length - index - 1 : index;
return (
<StepItem key={originalIndex} {...item} index={originalIndex} status={handleStatus(item, originalIndex)} />
);
});
}

const childrenList = React.Children.toArray(children);
const childrenDisplayList = sequence === 'reverse' ? childrenList.reverse() : childrenList;
const displayList = sequence === 'reverse' ? [...childrenList].reverse() : childrenList;

return childrenList.map((child: React.ReactElement<StepItemProps>, index: number) => {
const stepIndex = sequence === 'reverse' ? childrenDisplayList.length - index - 1 : index;
return displayList.map((child: React.ReactElement<StepItemProps>, index: number) => {
const originalIndex = sequence === 'reverse' ? displayList.length - index - 1 : index;
return React.cloneElement(child, {
...child.props,
index: stepIndex,
status: handleStatus(child.props, index),
index: originalIndex,
status: handleStatus(child.props, originalIndex),
});
});
}, [options, children, sequence, handleStatus]);
Expand Down
Loading
Loading