Skip to content
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

Improve keyboard accessibility of the codecard component #10405

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

microbit-robert
Copy link
Contributor

This affects code cards on the experiments page. At the moment, it is not possible to trigger the feedback link of these cards via keyboard, this action simple toggles the experiment on and off. This PR addresses this and also improves the appearance of the focus-visible outline around the "Beta Editor" card.

@microbit-matt-hillsdon

@@ -95,9 +102,18 @@ export class CodeCardView extends data.Component<CodeCardProps, CodeCardState> {
const ariaLabel = card.ariaLabel || card.title || card.shortName || name;

const style = card.style || "card"
const cardDiv = <div className={`ui ${style} ${color} ${card.onClick ? "link" : ''} ${className ? className : ''}`}
role={card.role} aria-selected={card.role === "option" ? "true" : undefined} aria-label={ariaLabel} title={card.title}
onClick={clickHandler} tabIndex={card.onClick ? card.tabIndex || 0 : null} onKeyDown={card.onClick ? fireClickOnEnter : null}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fireClickOnEnter does the wrong thing here when using "Enter" or "Space" while the "Feedback" anchor tag is focussed. It prevents the default behaviour, then triggers click on this element instead of the anchor tag from which the original event was triggered, causing the experiment to toggle on/off.

@abchatra abchatra requested review from Copilot and riknoll March 6, 2025 19:28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR improves keyboard accessibility and visual focus for code cards on the experiments page.

  • Change the interactive role from "button" to "link" for the Beta Editor card in scriptsearch.tsx.
  • Refactor and add a keyboard event handler (keydownHandler) in CodeCardView to trigger the click action on Enter and Space keys.

Reviewed Changes

File Description
webapp/src/scriptsearch.tsx Updated the role attribute for the Beta Editor card to support link behavior.
webapp/src/codecard.tsx Introduced a keydownHandler for keyboard interactivity and refactored rendering logic.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

webapp/src/scriptsearch.tsx:526

  • Verify that changing the role from 'button' to 'link' correctly reflects the element's behavior. Ensure that if a link is expected, the element provides appropriate navigation behavior (for example, a valid href) or that the change is aligned with the intended interaction.
role="link"

webapp/src/codecard.tsx:84

  • [nitpick] Consider defining named constants for the key codes (e.g., ENTER and SPACE) to improve the readability of the keydownHandler function.
const keydownHandler = (e: React.KeyboardEvent) => {
@riknoll riknoll merged commit b64e8c2 into microsoft:master Mar 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants