Skip to content

fix: prevent PanelStack2 from opening in the wrong direction #6847

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

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
Next Next commit
fix: prevent PanelStack2 from opening in the wrong direction
Fixes: #6723
  • Loading branch information
stropitek committed Jun 13, 2024
commit 5d0e8c293574fa04daa6556a926f27b8964031ed
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);
// Adjust the direction in case the stack size has changed, controlled or uncontrolled
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