-
Notifications
You must be signed in to change notification settings - Fork 153
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
base: master
Are you sure you want to change the base?
Conversation
Storybook staging is available at https://kiwicom-orbit-sarka-card-a11y.surge.sh |
Size Change: +218 B (+0.05%) Total Size: 459 kB
ℹ️ View Unchanged
|
Deploying orbit with Cloudflare Pages
|
245a5fa
to
7343393
Compare
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.
Key Issues
The use of both onClick
and role="button"
on a div is redundant and may lead to accessibility issues, as the div should not have button semantics when it is a wrapper for a button element.
7343393
to
06448f5
Compare
@@ -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 }) => ( |
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.
expandable={expandable} | ||
header={header} | ||
expanded={opened} | ||
actions={Boolean(actions)} |
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.
On this line, I convert actions to a boolean value. The reason is that Header
component renders ArrowButton
component in case when actions === null
. I want to avoid having this component present as actions are rendered below (if available). ⬇️
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I've added this React.isValisElement
function. In case we have actions
in CardSelection
component, then rendering actions
here is redundant. In case actions
is empty, we don't want to render <Stack>
element below at all.
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.
Feels a bit hacky, but it works for now
isSection | ||
/> | ||
</button> | ||
{actions && <Actions actions={actions} />} |
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.
Moved to render actions
here as well as we want separate actions
from Header component in case we're using this CardSection
component.
06448f5
to
9aaf8b0
Compare
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.
Key Issues
The handleClick
function incorrectly checks the opened
state before it is updated, leading to the invocation of the wrong callback function.
9aaf8b0
to
6864598
Compare
6864598
to
5f5e39a
Compare
<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 comment
The 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.
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.
An overcomplicated component that could be very much simplified. Out of our control for now.
Besides the change on stories, LGTM 👍 Good work
@@ -13,6 +13,15 @@ import { ELEMENT_OPTIONS } from "../Heading/consts"; | |||
|
|||
import Card from "."; | |||
|
|||
const CardSectionHeaderContent = () => ( |
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.
Doing this doesn't help the code snippet at all. I would rather keep it as it was
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit hacky, but it works for now
I got inspired here: https://kittygiraudel.com/2022/04/02/accessible-cards/#wrapping-up
Closes https://kiwicom.atlassian.net/browse/FEPLT-2196
This Pull Request meets the following criteria:
For new components:
d.ts
files and are exported inindex.d.ts
Closes: https://kiwicom.atlassian.net/browse/FEPLT-2196
✨
Description by Callstackai
This PR refactors the Card component and its related sections to enhance accessibility, including the introduction of new components for better structure and usability.
Diagrams of code changes
Files Changed