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: prevent PanelStack2 from opening in the wrong direction #6847

Merged
Merged
Changes from 1 commit
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
7 changes: 2 additions & 5 deletions packages/core/src/components/panel-stack2/panelStack2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,16 @@ export const PanelStack2: PanelStack2Component = <T extends Panel<object>>(props
stack: propsStack,
} = props;
const isControlled = propsStack != null;
const [direction, setDirection] = React.useState("push");

const [localStack, setLocalStack] = React.useState<T[]>(initialPanel !== undefined ? [initialPanel] : []);
const stack = React.useMemo(
() => (isControlled ? propsStack.slice().reverse() : localStack),
[localStack, isControlled, propsStack],
);
const stackLength = React.useRef<number>(stack.length);
stropitek marked this conversation as resolved.
Show resolved Hide resolved
// Adjust the direction in case the stack size has changed, controlled or uncontrolled
stropitek marked this conversation as resolved.
Show resolved Hide resolved
const direction = stack.length - stackLength.current < 0 ? "pop" : "push";
React.useEffect(() => {
if (stack.length !== stackLength.current) {
// Adjust the direction in case the stack size has changed, controlled or uncontrolled
setDirection(stack.length - stackLength.current < 0 ? "pop" : "push");
}
stackLength.current = stack.length;
}, [stack]);

Expand Down