From 162110de6d75aa1c2c28af7c05098b5ae963362b Mon Sep 17 00:00:00 2001 From: karmanya79 <108292683+karmanya79@users.noreply.github.com> Date: Fri, 18 Nov 2022 08:39:01 -0500 Subject: [PATCH] fix: Split-panel should have accessible name and consistent identification of regions (#490) --- .../__tests__/split-panel.test.tsx | 16 +++++++++++++++ src/split-panel/index.tsx | 20 +++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/split-panel/__tests__/split-panel.test.tsx b/src/split-panel/__tests__/split-panel.test.tsx index 83a9e1f8bb..aca01db97d 100644 --- a/src/split-panel/__tests__/split-panel.test.tsx +++ b/src/split-panel/__tests__/split-panel.test.tsx @@ -9,6 +9,7 @@ import { SplitPanelContextProps, } from '../../../lib/components/internal/context/split-panel-context'; import createWrapper, { SplitPanelWrapper } from '../../../lib/components/test-utils/dom'; +import styles from '../../../lib/components/split-panel/styles.css.js'; const onKeyDown = jest.fn(); jest.mock('../../../lib/components/split-panel/utils/use-keyboard-events', () => ({ @@ -277,4 +278,19 @@ describe('Split panel', () => { expect(sidePositionTileElement?.disabled).toBeTruthy(); }); }); + describe('has proper aria properties', () => { + test('split panel content has correct role', () => { + const { wrapper } = renderSplitPanel({ contextProps: { position: 'side' } }); + const sidePanelElem = wrapper.findByClassName(styles['drawer-content-side'])?.getElement(); + expect(sidePanelElem).toHaveAttribute('role', 'region'); + }); + + test('split panel is labelled by panel header', () => { + const { wrapper } = renderSplitPanel({ contextProps: { position: 'side' } }); + const sidePanelElem = wrapper.findByClassName(styles['drawer-content-side'])?.getElement(); + const labelId = sidePanelElem?.getAttribute('aria-labelledby'); + + expect(sidePanelElem?.querySelector(`#${labelId}`)!.textContent).toBe('Split panel header'); + }); + }); }); diff --git a/src/split-panel/index.tsx b/src/split-panel/index.tsx index 0058219636..9d550dd61e 100644 --- a/src/split-panel/index.tsx +++ b/src/split-panel/index.tsx @@ -23,6 +23,7 @@ import { getLimitedValue } from './utils/size-utils'; import { Transition, TransitionStatus } from '../internal/components/transition'; import { ButtonProps } from '../button/interfaces'; import { useEffectOnUpdate } from '../internal/hooks/use-effect-on-update'; +import { useUniqueId } from '../internal/hooks/use-unique-id'; export { SplitPanelProps }; @@ -43,6 +44,7 @@ interface TransitionContentProps { onSliderPointerDown: () => void; focusVisible: { 'data-awsui-focus-visible': true } | { 'data-awsui-focus-visible'?: undefined }; paneHeader: JSX.Element; + panelHeaderId: string; wrappedChildren: JSX.Element; } @@ -68,6 +70,7 @@ const TransitionContentSide = ({ focusVisible, toggleRef, paneHeader, + panelHeaderId, wrappedChildren, }: TransitionContentSideProps) => { return ( @@ -82,7 +85,7 @@ const TransitionContentSide = ({ }} ref={splitPanelRef} > - + ); }; @@ -168,6 +173,7 @@ const TransitionContentBottom = ({ centeredMaxWidthClasses, splitPanelHeaderRef, appLayoutMaxWidth, + panelHeaderId, }: TransitionContentBottomProps) => { const transitionContentBottomRef = useMergeRefs(splitPanelRef || null, transitioningElementRef); return ( @@ -208,7 +214,7 @@ const TransitionContentBottom = ({ )} -
+
{paneHeader}
@@ -349,9 +355,13 @@ export default function SplitPanel({ ); + const panelHeaderId = useUniqueId('split-panel-header'); + const paneHeader = (
-

{header}

+

+ {header} +

{!hidePreferencesButton && isOpen && ( <> @@ -460,6 +470,7 @@ export default function SplitPanel({ toggleRef={toggleRef} paneHeader={paneHeader} wrappedChildren={wrappedChildren} + panelHeaderId={panelHeaderId} > )} @@ -489,6 +500,7 @@ export default function SplitPanel({ centeredMaxWidthClasses={centeredMaxWidthClasses} splitPanelHeaderRef={splitPanelHeaderRef} appLayoutMaxWidth={appLayoutMaxWidth} + panelHeaderId={panelHeaderId} > )} {isPreferencesOpen && (