diff --git a/src/components/Navigation/SideBar/SideBar.test.tsx b/src/components/Navigation/SideBar/SideBar.test.tsx
index 162a14907..bcf36d8ed 100644
--- a/src/components/Navigation/SideBar/SideBar.test.tsx
+++ b/src/components/Navigation/SideBar/SideBar.test.tsx
@@ -146,3 +146,34 @@ test('Render Create button correctly when open', async () => {
const createButton = screen.getAllByRole('button')[0];
expect(createButton).toHaveStyleRule('height', '36px');
});
+
+test('Hides create button when showCreate=false', async () => {
+ const createLabel = faker.animal.dog();
+ const handleOnCreate = vi.fn();
+ window.localStorage.setItem(
+ 'amplify-sidebar-state',
+ JSON.stringify({ isOpen: false })
+ );
+ render(
+
+ {defaultMenuItems.map((m) => (
+
+ ))}
+ ,
+ { wrapper: SideBarProvider }
+ );
+ const user = userEvent.setup();
+
+ await user.click(screen.getAllByRole('button')[0]);
+
+ const icons = screen.getAllByTestId('eds-icon-path');
+ for (const icon of icons) {
+ expect(icon).not.toHaveAttribute('d', add.svgPathData);
+ }
+
+ expect(screen.queryByText(createLabel)).not.toBeInTheDocument();
+});
diff --git a/src/components/Navigation/SideBar/SideBar.tsx b/src/components/Navigation/SideBar/SideBar.tsx
index 3034e7941..889c0eeaf 100644
--- a/src/components/Navigation/SideBar/SideBar.tsx
+++ b/src/components/Navigation/SideBar/SideBar.tsx
@@ -45,6 +45,7 @@ const TopContainer = styled.div`
interface SidebarProps extends HTMLAttributes {
children: ReactNode;
+ showCreate?: boolean;
}
interface SideBarWithoutCreate extends SidebarProps {
@@ -61,7 +62,7 @@ export const SideBar = forwardRef<
HTMLDivElement,
SidebarWithCreate | SideBarWithoutCreate
>((props, ref) => {
- const { children } = props;
+ const { children, showCreate = true } = props;
const { isOpen, setIsOpen } = useSideBar();
const handleToggle = () => {
@@ -75,7 +76,7 @@ export const SideBar = forwardRef<
data-testid="sidebar"
>
- {props.onCreate && (
+ {props.onCreate && showCreate && (