-
Notifications
You must be signed in to change notification settings - Fork 152
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
Card: refactor component for improved accessibility #4574
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) => ( | ||
<Stack inline grow={false} justify="end"> | ||
{actions} | ||
</Stack> | ||
); | ||
|
||
export default function CardSection({ | ||
title, | ||
|
@@ -68,24 +75,35 @@ export default function CardSection({ | |
onKeyDown={onClick == null ? undefined : handleKeyDown(onClick)} | ||
> | ||
{(title != null || header != null) && expandable && ( | ||
<button | ||
type="button" | ||
className="p-400 lm:p-600 hover:bg-white-normal-hover w-full" | ||
aria-expanded={opened} | ||
aria-controls={slideID} | ||
onClick={handleClick} | ||
<div | ||
className={cx( | ||
"hover:bg-white-normal-hover p-400 lm:p-600 gap-300 relative z-10 flex cursor-pointer items-center", | ||
"has-[.orbit-card-header-button:focus]:focus-within:rounded-100 has-[.orbit-card-header-button:focus]:focus-within:outline-blue-normal has-[.orbit-card-header-button:focus]:focus-within:outline has-[.orbit-card-header-button:focus]:focus-within:outline-2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is not defined focus state for this specific element, I set 2px solid blue outline value, as it is used for example in InputGroup component. |
||
)} | ||
> | ||
<Header | ||
title={title} | ||
titleAs={titleAs} | ||
description={description} | ||
expandable={expandable} | ||
header={header} | ||
expanded={opened} | ||
actions={actions} | ||
isSection | ||
/> | ||
</button> | ||
<button | ||
type="button" | ||
className={cx( | ||
"orbit-card-header-button w-full focus:outline-none", | ||
"before:absolute before:inset-0", | ||
)} | ||
aria-expanded={opened} | ||
aria-controls={slideID} | ||
onClick={handleClick} | ||
> | ||
<Header | ||
title={title} | ||
titleAs={titleAs} | ||
description={description} | ||
expandable={expandable} | ||
header={header} | ||
expanded={opened} | ||
actions={Boolean(actions)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this line, I convert actions to a boolean value. The reason is that |
||
isSection | ||
/> | ||
</button> | ||
{actions && <Actions actions={actions} />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to render |
||
</div> | ||
)} | ||
|
||
{(title != null || header != null) && !expandable && ( | ||
|
@@ -100,6 +118,7 @@ export default function CardSection({ | |
actions={actions} | ||
isSection | ||
/> | ||
{actions && <Actions actions={actions} />} | ||
</div> | ||
)} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ const Header = ({ | |
color="secondary" | ||
/> | ||
)} | ||
{actions && ( | ||
{React.isValidElement(actions) && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels a bit hacky, but it works for now |
||
<Stack inline grow={false} justify="end"> | ||
{actions} | ||
</Stack> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this small component because the of avoiding the code duplication as it's used twice within this file.