Skip to content

Commit

Permalink
fix: Prevent collapsed bottom split panel from covering content (#3144)
Browse files Browse the repository at this point in the history
  • Loading branch information
jperals authored Dec 17, 2024
1 parent 468db9e commit 07df1aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/app-layout/__integ__/app-layout-split-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as const)('%s', theme =>
})
);

test(
'avoids covering the page content when collapsed at the bottom',
setupTest(async page => {
const splitPanel = wrapper.findSplitPanel();
const splitPanelSelector = wrapper.findSplitPanel().toSelector();
const contentSelector = wrapper.findContentRegion().findSpaceBetween().toSelector();
await expect(page.isExisting(splitPanel.findOpenButton().toSelector())).resolves.toBe(true);
await page.windowScrollTo({ top: 1000 });
const { top: splitPAnelTop } = await page.getBoundingBox(splitPanelSelector);
const { bottom: contentBottom } = await page.getBoundingBox(contentSelector);
expect(splitPAnelTop).toBeGreaterThanOrEqual(contentBottom);
})
);

describe('interaction with table sticky header', () => {
// bottom padding is included into the offset in VR but not in classic
const splitPanelPadding = theme === 'refresh' ? 40 : 0;
Expand Down
13 changes: 9 additions & 4 deletions src/app-layout/visual-refresh-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
);

const [splitPanelReportedSize, setSplitPanelReportedSize] = useState(0);
const [splitPanelHeaderBlockSize, setSplitPanelHeaderBlockSize] = useState(0);

const onSplitPanelResizeHandler = (size: number) => {
setSplitPanelSize(size);
Expand Down Expand Up @@ -362,9 +363,8 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
onToggle: onSplitPanelToggleHandler,
position: splitPanelPosition,
reportSize: size => setSplitPanelReportedSize(size),
reportHeaderHeight: () => {
/*unused in this design*/
},
reportHeaderHeight: size => setSplitPanelHeaderBlockSize(size),
headerHeight: splitPanelHeaderBlockSize,
rightOffset: 0,
size: splitPanelSize,
topOffset: 0,
Expand Down Expand Up @@ -467,7 +467,12 @@ const AppLayoutVisualRefreshToolbar = React.forwardRef<AppLayoutProps.Ref, AppLa
<SkeletonLayout
ref={useMergeRefs(intersectionObserverRef, rootRef)}
style={{
paddingBlockEnd: splitPanelOpen && splitPanelPosition === 'bottom' ? splitPanelReportedSize : '',
paddingBlockEnd:
splitPanelPosition === 'bottom'
? splitPanelOpen
? splitPanelReportedSize
: splitPanelHeaderBlockSize
: '',
...(hasToolbar || !isNested
? {
[globalVars.stickyVerticalTopOffset]: `${verticalOffsets.header}px`,
Expand Down
1 change: 1 addition & 0 deletions src/internal/context/split-panel-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface SplitPanelContextBaseProps {
onToggle: () => void;
onPreferencesChange: (detail: { position: 'side' | 'bottom' }) => void;
reportHeaderHeight: (pixels: number) => void;
headerHeight?: number;
setSplitPanelToggle: (config: SplitPanelSideToggleProps) => void;
refs: SplitPanelFocusControlRefs;
}
Expand Down
5 changes: 2 additions & 3 deletions src/split-panel/bottom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef } from 'react';
import clsx from 'clsx';

import { useResizeObserver } from '@cloudscape-design/component-toolkit/internal';
Expand Down Expand Up @@ -41,16 +41,15 @@ export function SplitPanelContentBottom({
disableContentPaddings,
contentWrapperPaddings,
reportHeaderHeight,
headerHeight: headerBlockSize,
animationDisabled,
} = useSplitPanelContext();
const isMobile = useMobile();

const headerRef = useRef<HTMLDivElement>(null);
const [headerBlockSize, setHeaderBlockSize] = useState<number>();

useResizeObserver(headerRef, entry => {
const { borderBoxHeight } = entry;
setHeaderBlockSize(borderBoxHeight);
reportHeaderHeight(borderBoxHeight);
});

Expand Down

0 comments on commit 07df1aa

Please sign in to comment.