Skip to content

Commit

Permalink
fix: prevent PanelStack2 from opening in the wrong direction (#6847)
Browse files Browse the repository at this point in the history
  • Loading branch information
stropitek authored Jun 26, 2024
1 parent f35e0da commit 605d318
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/core/src/components/panel-stack2/panelStack2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as React from "react";
import { CSSTransition, TransitionGroup } from "react-transition-group";

import { Classes, DISPLAYNAME_PREFIX, type Props } from "../../common";
import { usePrevious } from "../../hooks";

import type { Panel } from "./panelTypes";
import { PanelView2 } from "./panelView2";
Expand Down Expand Up @@ -97,21 +98,14 @@ 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);
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]);
const prevStackLength = usePrevious(stack.length) ?? stack.length;
const direction = stack.length - prevStackLength < 0 ? "pop" : "push";

const handlePanelOpen = React.useCallback(
(panel: T) => {
Expand Down

1 comment on commit 605d318

@svc-palantir-github
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.