From 88e2063b8fc9aacf0438d739e0251e3c3c0c4c99 Mon Sep 17 00:00:00 2001 From: Avinash Dwarapu Date: Fri, 25 Aug 2023 16:23:03 +0200 Subject: [PATCH 1/8] revert: Revert "fix: Refactor and fix AppLayout and side navigation panel state and behaviour" (#1485) --- pages/side-navigation/app-layout.page.tsx | 11 +- src/app-layout/__tests__/common.test.tsx | 333 +++++++++--------- src/app-layout/__tests__/mobile.test.tsx | 128 ++----- src/app-layout/__tests__/utils.tsx | 6 +- src/app-layout/index.tsx | 20 +- src/app-layout/visual-refresh/context.tsx | 22 +- .../expandable-section-header.tsx | 3 +- src/side-navigation/internal.tsx | 3 + 8 files changed, 207 insertions(+), 319 deletions(-) diff --git a/pages/side-navigation/app-layout.page.tsx b/pages/side-navigation/app-layout.page.tsx index cc20c50f7f..e202c6e7f8 100644 --- a/pages/side-navigation/app-layout.page.tsx +++ b/pages/side-navigation/app-layout.page.tsx @@ -4,7 +4,6 @@ import React from 'react'; import SideNavigation, { SideNavigationProps } from '~components/side-navigation'; import AppLayout from '~components/app-layout'; import Badge from '~components/badge'; -import labels from '../app-layout/utils/labels'; import logoSmall from './logos/logo-small.svg'; @@ -102,16 +101,12 @@ const items: SideNavigationProps.Item[] = [ ]; export default function SideNavigationPage() { - const [open, setOpen] = React.useState(true); - return ( { - setOpen(detail.open); - }} + toolsHide={true} + navigationOpen={true} contentType="form" - ariaLabels={labels} + ariaLabels={{ navigationClose: 'Close' }} navigation={ ({ useContainerQuery: () => [100, () => {}], })); -describeEachAppLayout(size => { +describeEachAppLayout(() => { test('Default state', () => { const { wrapper } = renderComponent(); @@ -50,7 +50,6 @@ describeEachAppLayout(size => { openProp: 'navigationOpen', hideProp: 'navigationHide', handler: 'onNavigationChange', - expectedCallsOnMobileToggle: 2, findLandmarks: (wrapper: AppLayoutWrapper) => wrapper.findAll('nav'), findElement: (wrapper: AppLayoutWrapper) => wrapper.findNavigation(), findToggle: (wrapper: AppLayoutWrapper) => wrapper.findNavigationToggle(), @@ -60,182 +59,170 @@ describeEachAppLayout(size => { openProp: 'toolsOpen', hideProp: 'toolsHide', handler: 'onToolsChange', - expectedCallsOnMobileToggle: 1, findLandmarks: (wrapper: AppLayoutWrapper) => wrapper.findAll('aside'), findElement: (wrapper: AppLayoutWrapper) => wrapper.findTools(), findToggle: (wrapper: AppLayoutWrapper) => wrapper.findToolsToggle(), findClose: (wrapper: AppLayoutWrapper) => wrapper.findToolsClose(), }, - ].forEach( - ({ - openProp, - hideProp, - handler, - expectedCallsOnMobileToggle, - findElement, - findLandmarks, - findToggle, - findClose, - }) => { - describe(`${openProp} prop`, () => { - test(`Should call handler once on open when toggle is clicked`, () => { - const onToggle = jest.fn(); - const props = { - [openProp]: false, - [handler]: onToggle, - }; - const { wrapper } = renderComponent(); - - findToggle(wrapper).click(); - expect(onToggle).toHaveBeenCalledTimes(size === 'mobile' ? expectedCallsOnMobileToggle : 1); - expect(onToggle).toHaveBeenLastCalledWith(expect.objectContaining({ detail: { open: true } })); - }); - - test(`Should call handler once on open when span inside toggle is clicked`, () => { - const onToggle = jest.fn(); - const props = { - [openProp]: false, - [handler]: onToggle, - }; - const { wrapper } = renderComponent(); - - // Chrome bubbles up events from specific elements inside diff --git a/src/side-navigation/internal.tsx b/src/side-navigation/internal.tsx index 601a9e54b2..66048ce75c 100644 --- a/src/side-navigation/internal.tsx +++ b/src/side-navigation/internal.tsx @@ -227,6 +227,9 @@ function Link({ definition, expanded, activeHref, fireFollow }: LinkProps) { const onClick = useCallback( (event: React.MouseEvent) => { + // Prevent the click event from toggling outer expandable sections. + event.stopPropagation(); + if (isPlainLeftClick(event)) { fireFollow(definition, event); } From ea396d805c91e6b422323e011e4c0a93066ffa86 Mon Sep 17 00:00:00 2001 From: Katie George Date: Fri, 25 Aug 2023 09:01:26 -0700 Subject: [PATCH 2/8] fix: Fixes aria expanded and aria controls in AppLayout (#1479) Co-authored-by: Katie George --- src/app-layout/__tests__/common.test.tsx | 9 +++++++- src/app-layout/__tests__/desktop.test.tsx | 7 ++++++ src/app-layout/drawer/index.tsx | 22 ++++++++++++++++--- src/app-layout/mobile-toolbar/index.tsx | 4 ++-- src/app-layout/toggles/index.tsx | 16 ++++++++++++-- src/app-layout/toggles/interfaces.ts | 1 + src/app-layout/visual-refresh/context.tsx | 7 ++++++ src/app-layout/visual-refresh/drawers.tsx | 11 +++++++++- src/app-layout/visual-refresh/navigation.tsx | 1 + src/app-layout/visual-refresh/split-panel.tsx | 2 ++ src/app-layout/visual-refresh/tools.tsx | 7 ++++++ .../visual-refresh/trigger-button.tsx | 18 +++++++++++++-- src/button-dropdown/interfaces.ts | 1 + src/button-dropdown/internal.tsx | 1 + 14 files changed, 96 insertions(+), 11 deletions(-) diff --git a/src/app-layout/__tests__/common.test.tsx b/src/app-layout/__tests__/common.test.tsx index 9d38156c59..8b5710e8bf 100644 --- a/src/app-layout/__tests__/common.test.tsx +++ b/src/app-layout/__tests__/common.test.tsx @@ -148,7 +148,13 @@ describeEachAppLayout(() => { }); test('Renders aria-expanded only on toggle', () => { - const { wrapper } = renderComponent(); + const props = { + [openProp]: false, + [handler]: () => {}, + }; + + const { wrapper } = renderComponent(); + expect(findToggle(wrapper).getElement()).toHaveAttribute('aria-expanded', 'false'); expect(findToggle(wrapper).getElement()).toHaveAttribute('aria-haspopup', 'true'); expect(findClose(wrapper).getElement()).not.toHaveAttribute('aria-expanded'); @@ -281,6 +287,7 @@ describeEachAppLayout(() => { expect(wrapper.findDrawersTriggers()![0].getElement()).toHaveAttribute('aria-expanded', 'false'); expect(wrapper.findDrawersTriggers()![0].getElement()).toHaveAttribute('aria-haspopup', 'true'); wrapper.findDrawersTriggers()![0].click(); + expect(wrapper.findDrawersTriggers()![0].getElement()).toHaveAttribute('aria-expanded', 'true'); expect(wrapper.findActiveDrawerCloseButton()!.getElement()).not.toHaveAttribute('aria-expanded'); expect(wrapper.findActiveDrawerCloseButton()!.getElement()).not.toHaveAttribute('aria-haspopup'); }); diff --git a/src/app-layout/__tests__/desktop.test.tsx b/src/app-layout/__tests__/desktop.test.tsx index 1f7509f07e..78dff81cf2 100644 --- a/src/app-layout/__tests__/desktop.test.tsx +++ b/src/app-layout/__tests__/desktop.test.tsx @@ -240,6 +240,13 @@ describeEachThemeAppLayout(false, () => { expect(wrapper.findDrawersTriggers()!.length).toBeLessThan(100); }); + + test('Renders aria-controls on toggle only when active', () => { + const { wrapper } = renderComponent(); + expect(wrapper.findDrawersTriggers()![0].getElement()).not.toHaveAttribute('aria-controls'); + act(() => wrapper.findDrawersTriggers()![0].click()); + expect(wrapper.findDrawersTriggers()![0].getElement()).toHaveAttribute('aria-controls', 'security'); + }); }); // In VR we use a custom CSS property so we cannot test the style declaration. diff --git a/src/app-layout/drawer/index.tsx b/src/app-layout/drawer/index.tsx index 164f9daf78..6ae0e0b79f 100644 --- a/src/app-layout/drawer/index.tsx +++ b/src/app-layout/drawer/index.tsx @@ -66,13 +66,14 @@ export const Drawer = React.forwardRef( iconName={iconName} ariaLabel={openLabel} onClick={() => onToggle(true)} - ariaExpanded={false} + ariaExpanded={isOpen ? undefined : false} /> ); return (
void }> ) => (
@@ -152,6 +164,7 @@ const DrawerTrigger = React.forwardRef( iconSvg={trigger.iconSvg} ariaLabel={ariaLabel} ariaExpanded={ariaExpanded} + ariaControls={ariaControls} badge={badge} testId={itemId && `awsui-app-layout-trigger-${itemId}`} /> @@ -189,6 +202,8 @@ export const DrawerTriggersBar = ({ isMobile, topOffset, bottomOffset, drawers } ref={triggersContainerRef} style={{ top: topOffset, bottom: bottomOffset }} className={clsx(styles['drawer-content'])} + role="toolbar" + aria-orientation="vertical" > {!isMobile && (