Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(steps): make active step controlled via props #7300

Merged
merged 1 commit into from
Oct 2, 2024
Merged
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
11 changes: 4 additions & 7 deletions components/lib/steps/Steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const Steps = React.memo(
const props = StepsBase.getProps(inProps, context);

const [idState, setIdState] = React.useState(props.id);
const [activeIndexState, setActiveIndexState] = React.useState(props.activeIndex);
const elementRef = React.useRef(null);
const listRef = React.useRef(null);
const count = React.Children.count(props.children);
Expand All @@ -21,7 +20,7 @@ export const Steps = React.memo(
props,
state: {
id: idState,
activeIndex: activeIndexState
activeIndex: props.activeIndex
}
};

Expand All @@ -40,7 +39,7 @@ export const Steps = React.memo(
count,
first: index === 0,
last: index === count - 1,
active: index === activeIndexState,
active: index === props.activeIndex,
disabled: getStepProp(step, 'disabled')
}
};
Expand Down Expand Up @@ -73,8 +72,6 @@ export const Steps = React.memo(
});
}

setActiveIndexState(index);

if (!item.url) {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -191,8 +188,8 @@ export const Steps = React.memo(
}

const key = item.id || idState + '_' + index;
const active = index === activeIndexState;
const disabled = item.disabled || (index !== activeIndexState && props.readOnly);
const active = index === props.activeIndex;
const disabled = item.disabled || (index !== props.activeIndex && props.readOnly);

const iconClassName = classNames('p-menuitem-icon', item.icon);
const iconProps = mergeProps(
Expand Down
Loading