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

feat: Mimics tools behavior when there is only one drawer #1572

Merged
merged 1 commit into from
Sep 25, 2023
Merged
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
14 changes: 14 additions & 0 deletions src/app-layout/__tests__/desktop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ describe('Classic only features', () => {

expect(wrapper.findByClassName(iconStyles.badge)!.getElement()).toBeInTheDocument();
});

test(`should toggle single drawer on click of container`, () => {
const { wrapper } = renderComponent(<AppLayout contentType="form" toolsHide={true} {...singleDrawer} />);
act(() => wrapper.findDrawersDesktopTriggersContainer()!.click());
expect(wrapper.findActiveDrawer()).toBeTruthy();
act(() => wrapper.findDrawersDesktopTriggersContainer()!.click());
expect(wrapper.findActiveDrawer()).toBeFalsy();
});

test(`should not toggle many drawers on click of container`, () => {
const { wrapper } = renderComponent(<AppLayout contentType="form" toolsHide={true} {...manyDrawers} />);
act(() => wrapper.findDrawersDesktopTriggersContainer()!.click());
expect(wrapper.findActiveDrawer()).toBeFalsy();
});
});

describe('VR only features', () => {
Expand Down
18 changes: 14 additions & 4 deletions src/app-layout/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,24 @@ export const DrawerTriggersBar = ({ isMobile, topOffset, bottomOffset, drawers }
<div
className={clsx(styles.drawer, styles['drawer-closed'], testutilStyles['drawer-closed'], {
[styles['drawer-mobile']]: isMobile,
[styles.hide]: drawers?.items.length === 1 && drawers.activeDrawerId !== undefined,
})}
ref={containerRef}
>
<div
ref={triggersContainerRef}
style={{ top: topOffset, bottom: bottomOffset }}
className={clsx(styles['drawer-content'])}
className={clsx(styles['drawer-content'], {
[styles['drawer-content-clickable']]: drawers?.items.length === 1,
})}
role="toolbar"
aria-orientation="vertical"
onClick={() => {
drawers?.items.length === 1 &&
drawers?.onChange({
activeDrawerId: drawers.items[0].id !== drawers.activeDrawerId ? drawers.items[0].id : undefined,
});
}}
>
{!isMobile && (
<aside
Expand All @@ -229,9 +238,10 @@ export const DrawerTriggersBar = ({ isMobile, topOffset, bottomOffset, drawers }
itemId={item.id}
isActive={drawers?.activeDrawerId === item.id}
onClick={() => {
drawers?.onChange({
activeDrawerId: item.id !== drawers.activeDrawerId ? item.id : undefined,
});
drawers?.items.length !== 1 &&
drawers?.onChange({
activeDrawerId: item.id !== drawers.activeDrawerId ? item.id : undefined,
});
}}
/>
);
Expand Down
11 changes: 11 additions & 0 deletions src/app-layout/drawer/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,15 @@ $drawer-z-index-mobile: 1001;
background-color: awsui.$color-background-layout-toggle-selected-default;
color: awsui.$color-text-layout-toggle-active;
}
.drawer-triggers-wrapper > & {
.drawer-content-clickable > & {
&:hover {
color: awsui.$color-text-interactive-default;
}
}
}
}

.hide {
display: none;
}
3 changes: 3 additions & 0 deletions src/app-layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ const OldAppLayout = React.forwardRef(

if (hasDrawers) {
if (activeDrawer) {
if (drawers.length === 1) {
return activeDrawerSize;
}
if (!isResizeInvalid && activeDrawerSize) {
return activeDrawerSize + closedDrawerWidth;
}
Expand Down
Loading