From 9aaf8b0f421c1e42e4339a35abc5c51ad92c1a5b Mon Sep 17 00:00:00 2001 From: Sarka Chwastkova Date: Fri, 10 Jan 2025 17:21:58 +0100 Subject: [PATCH] feat(Card): refactor component for improved accessibility --- .../src/Card/Card.stories.tsx | 2 +- .../src/Card/CardSection/index.tsx | 53 +++++++++++++------ .../src/Card/components/Header.tsx | 2 +- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/packages/orbit-components/src/Card/Card.stories.tsx b/packages/orbit-components/src/Card/Card.stories.tsx index 98f4887ede..b8c9d96184 100644 --- a/packages/orbit-components/src/Card/Card.stories.tsx +++ b/packages/orbit-components/src/Card/Card.stories.tsx @@ -269,7 +269,7 @@ export const CardWithDefaultExpanded: Story = { } onClose={action("onClose")} header={ - + Trip length: 1h55m } type="warningSubtle"> Unavailable diff --git a/packages/orbit-components/src/Card/CardSection/index.tsx b/packages/orbit-components/src/Card/CardSection/index.tsx index 5551bc7631..891a49ea80 100644 --- a/packages/orbit-components/src/Card/CardSection/index.tsx +++ b/packages/orbit-components/src/Card/CardSection/index.tsx @@ -9,6 +9,13 @@ import type { Props } from "./types"; import Header from "../components/Header"; import Expandable from "./components/Expandable"; import handleKeyDown from "../../utils/handleKeyDown"; +import Stack from "../../Stack"; + +const Actions = ({ actions }) => ( + + {actions} + +); export default function CardSection({ title, @@ -68,24 +75,35 @@ export default function CardSection({ onKeyDown={onClick == null ? undefined : handleKeyDown(onClick)} > {(title != null || header != null) && expandable && ( - + + {actions && } + )} {(title != null || header != null) && !expandable && ( @@ -100,6 +118,7 @@ export default function CardSection({ actions={actions} isSection /> + {actions && } )} diff --git a/packages/orbit-components/src/Card/components/Header.tsx b/packages/orbit-components/src/Card/components/Header.tsx index 58e299d25f..1e25aecc24 100644 --- a/packages/orbit-components/src/Card/components/Header.tsx +++ b/packages/orbit-components/src/Card/components/Header.tsx @@ -68,7 +68,7 @@ const Header = ({ color="secondary" /> )} - {actions && ( + {React.isValidElement(actions) && ( {actions}