Skip to content

Commit

Permalink
fix(SidePanel): remove scrollTop behavior (#5376)
Browse files Browse the repository at this point in the history
* fix(SidePanel): remove scrollTop behavior

* fix: add back scrollTop but only apply on currentStep change
  • Loading branch information
matthewgallo committed Jun 13, 2024
1 parent a7db99d commit ee2897a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/ibm-products/src/components/SidePanel/SidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export let SidePanel = React.forwardRef(
const titleRef = useRef<HTMLDivElement>(null);
const labelTextRef = useRef<HTMLParagraphElement>(null);
const subtitleRef = useRef<HTMLParagraphElement>(null);
const previousState = usePreviousValue({ size, open });
const previousState = usePreviousValue({ size, open, currentStep });
const [scrollAnimationDistance, setScrollAnimationDistance] = useState(-1);
const [doAnimateTitle, setDoAnimateTitle] = useState(true);
const { firstElement, keyDownListener } = useFocus(sidePanelRef);
Expand Down Expand Up @@ -361,9 +361,14 @@ export let SidePanel = React.forwardRef(
const scrollableSection =
animatedScrollRef.current ?? innerContentRef.current;

if (scrollableSection) {
if (
previousState &&
previousState['currentStep'] !== currentStep &&
scrollableSection
) {
scrollableSection.scrollTop = 0;
}

// The size of the panel has changed while it is still opened
// so we need to scroll it to the top and reset the header
// height css custom property
Expand Down
1 change: 1 addition & 0 deletions packages/ibm-products/src/custom-typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@ declare module '@carbon/react' {
}

declare module '@carbon/colors';
declare module '@carbon/motion';
declare module '@carbon/feature-flags';

0 comments on commit ee2897a

Please sign in to comment.