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

refactor(sidebar): use CSS solution for overflow on sidebar content when no sticky footer detected FE-6642 #6997

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/components/form/form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const Form = ({
</StyledFormContent>
{renderFooter && (
<StyledFormFooter
data-component="form-footer"
data-element="form-footer"
data-role="form-footer"
className={classNames}
Expand Down
19 changes: 4 additions & 15 deletions src/components/sidebar/sidebar.component.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React, { useCallback, useRef, useMemo } from "react";
import React, { useCallback, useRef } from "react";
import { PaddingProps, WidthProps } from "styled-system";

import Modal, { ModalProps } from "../modal";
import StyledSidebar from "./sidebar.style";
import StyledSidebar, { StyledSidebarContent } from "./sidebar.style";
import IconButton from "../icon-button";
import Icon from "../icon";
import { FormProps } from "../form";
import FocusTrap from "../../__internal__/focus-trap";
import SidebarHeader from "./__internal__/sidebar-header";
import Box from "../box";
import createGuid from "../../__internal__/utils/helpers/guid";
import useLocale from "../../hooks/__internal__/useLocale";
import { filterStyledSystemPaddingProps } from "../../style/utils";
Expand Down Expand Up @@ -119,14 +117,6 @@ export const Sidebar = React.forwardRef<HTMLDivElement, SidebarProps>(
) => {
const locale = useLocale();
const { current: headerId } = useRef<string>(createGuid());
const hasStickyFooter = useMemo(
() =>
React.Children.toArray(children).some(
(child) =>
React.isValidElement<FormProps>(child) && child.props.stickyFooter
),
[children]
);

const sidebarRef = useRef<HTMLDivElement | null>(null);

Expand Down Expand Up @@ -184,21 +174,20 @@ export const Sidebar = React.forwardRef<HTMLDivElement, SidebarProps>(
</SidebarHeader>
)}
{!header && closeIcon()}
<Box
<StyledSidebarContent
data-element="sidebar-content"
data-role="sidebar-content"
pt="var(--spacing300)"
pb="var(--spacing400)"
px="var(--spacing400)"
{...filterStyledSystemPaddingProps(rest)}
scrollVariant="light"
overflow={hasStickyFooter ? undefined : "auto"}
flex="1"
>
<SidebarContext.Provider value={{ isInSidebar: true }}>
{children}
</SidebarContext.Provider>
</Box>
</StyledSidebarContent>
</StyledSidebar>
);

Expand Down
7 changes: 7 additions & 0 deletions src/components/sidebar/sidebar.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "../../style/utils/form-style-utils";
import { StyledFormContent, StyledFormFooter } from "../form/form.style";
import { SIDEBAR_SIZES_CSS } from "./sidebar.config";
import Box from "../box";

type StyledSidebarProps = Pick<
SidebarProps,
Expand Down Expand Up @@ -70,6 +71,12 @@ const StyledSidebar = styled.div<StyledSidebarProps>`
`}
`;

export const StyledSidebarContent = styled(Box)`
&:not(:has(${StyledFormFooter}.sticky)) {
overflow-y: auto;
}
`;

StyledSidebar.defaultProps = {
theme: baseTheme,
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ test("ensures overflowing content is scrollable", () => {
test("does not control styling of overflowing content when there is a child Form with a sticky footer", () => {
render(
<Sidebar open>
<Form stickyFooter />
<Form stickyFooter rightSideButtons={<span>foo</span>} />
</Sidebar>
);

Expand Down
Loading