diff --git a/src/components/Drawer/Drawer.tsx b/src/components/Drawer/Drawer.tsx index d8643a23..b6ec0b36 100644 --- a/src/components/Drawer/Drawer.tsx +++ b/src/components/Drawer/Drawer.tsx @@ -1,4 +1,11 @@ -import React, { Children, cloneElement, ReactElement, useEffect, useRef } from "react"; +import React, { + Children, + cloneElement, + isValidElement, + ReactElement, + useEffect, + useRef, +} from "react"; import { createPortal } from "react-dom"; import ReactFocusLock from "react-focus-lock"; import { SerializedStyles } from "@emotion/react"; @@ -70,6 +77,9 @@ const Drawer: FCWithChildren & DrawerCompoundProps = (props) => { onClose, ...rest } = props; + const hasHeader = Children.toArray(children).some( + (child) => isValidElement(child) && child.type === Header, + ); const clonedChildren = Children.map(children, (child) => { return ( child && @@ -154,6 +164,7 @@ const Drawer: FCWithChildren & DrawerCompoundProps = (props) => { aria-expanded={isOpen} aria-hidden={!isOpen} aria-modal="true" + aria-labelledby={hasHeader ? "drawer-title" : undefined} initial="initial" animate="expanded" exit="initial" diff --git a/src/components/Drawer/__snapshots__/Drawer.test.tsx.snap b/src/components/Drawer/__snapshots__/Drawer.test.tsx.snap index 6c685e1b..c8e6c57a 100644 --- a/src/components/Drawer/__snapshots__/Drawer.test.tsx.snap +++ b/src/components/Drawer/__snapshots__/Drawer.test.tsx.snap @@ -21,13 +21,14 @@ exports[` matches snapshot with close button 1`] = ` -
@@ -49,7 +50,7 @@ exports[` matches snapshot with close button 1`] = ` /> -
+
matches snapshot with header, body and footer 1`] = ` -
@@ -110,18 +112,18 @@ exports[` matches snapshot with header, body and footer 1`] = ` /> -
+
Test body
-
Test footer -
+
matches snapshot with noGutters Header 1`] = ` -
@@ -181,7 +184,7 @@ exports[` matches snapshot with noGutters Header 1`] = ` /> -
+
matches snapshot with right placement 1`] = ` -
@@ -241,7 +245,7 @@ exports[` matches snapshot with right placement 1`] = ` /> -
+
( -
+
{children} -
+
); export default Footer; diff --git a/src/components/Drawer/components/Header.tsx b/src/components/Drawer/components/Header.tsx index 94024ce7..b2993ae8 100644 --- a/src/components/Drawer/components/Header.tsx +++ b/src/components/Drawer/components/Header.tsx @@ -15,7 +15,8 @@ const Header: FCWithChildren = ({ onClose, noGutters = false, child const title = typeof children === "string" ? {children} : children; return ( -
drawerHeader({ noGutters })} @@ -32,7 +33,7 @@ const Header: FCWithChildren = ({ onClose, noGutters = false, child > -
+ ); }; diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 1433c373..e2f02be4 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -13,7 +13,7 @@ export type HeaderProps = React.HTMLAttributes & { const Header: FC = ({ children, onClose, ...rest }) => { const title = typeof children === "string" ? {children} : children; return ( -
+
{title}
{onClose && ( )} -
+ ); }; @@ -44,9 +44,9 @@ type FooterProps = React.HTMLAttributes; const Footer: FC = ({ children, ...rest }) => { return ( -
+
{children} -
+ ); }; diff --git a/src/components/Modal/__snapshots__/Modal.test.tsx.snap b/src/components/Modal/__snapshots__/Modal.test.tsx.snap index 731a2c1d..ac1751ad 100644 --- a/src/components/Modal/__snapshots__/Modal.test.tsx.snap +++ b/src/components/Modal/__snapshots__/Modal.test.tsx.snap @@ -8,7 +8,7 @@ exports[` matches snapshot 1`] = ` role="dialog" tabindex="-1" > -
@@ -19,18 +19,18 @@ exports[` matches snapshot 1`] = ` Test header -
+
Test body
-
Test footer -
+ `; @@ -43,7 +43,7 @@ exports[` matches snapshot with all props 1`] = ` style="border: 3px solid red;" tabindex="-1" > -
@@ -54,7 +54,7 @@ exports[` matches snapshot with all props 1`] = ` Test header -
+
matches snapshot with all props 1`] = ` type="password" />
-
matches snapshot with all props 1`] = ` -
+ `; @@ -105,7 +105,7 @@ exports[` matches snapshot with custom HTML classes 1`] = ` role="dialog" tabindex="-1" > -
@@ -116,17 +116,17 @@ exports[` matches snapshot with custom HTML classes 1`] = ` Test header -
+
Test body
- + `;