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

Correctly handle link interactions on extension cards #10406

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

microbit-robert
Copy link
Contributor

When using the keyboard, the "Learn More" links both open a link in a new tab and add the extension to the project when only the former should happen.

In the beta editor, the extension card "Learn More" links are now anchor tags instead of buttons. Some additional click handling is required to prevent the same keyboard error noted above also occuring when clicking these links.

This PR addresses both issues.

@microbit-matt-hillsdon

@abchatra abchatra requested review from riknoll and Copilot and removed request for riknoll March 6, 2025 19:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes an issue where using the keyboard on extension card "Learn More" links mistakenly triggers both opening a new tab and adding the extension to the project. The changes introduce dedicated click and keydown handlers to ensure that clicks on anchor tags aren’t misinterpreted as card selection events.

  • Added a unified handler (handleLinkOrTriggerClick) that differentiates between anchor clicks and other interactions.
  • Updated onClick and onKeyDown event bindings to use the new handlers.

Reviewed Changes

File Description
react-common/components/controls/Card.tsx Introduced specialized event handlers for mouse and keyboard events to prevent undesired behavior when interacting with anchor ("Learn More") links.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

react-common/components/controls/Card.tsx:42

  • Consider using e.key instead of charCode to handle keyboard events in a more modern and readable way.
const charCode = (typeof e.which == "number") ? e.which : e.keyCode;

Comment on lines +30 to +31
if (e.target && (e.target as HTMLElement).tagName == "A") {
return;
Copy link
Preview

Copilot AI Mar 6, 2025

Choose a reason for hiding this comment

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

Consider checking if the clicked element or any of its ancestors is an anchor tag to handle cases where a child element within the anchor is clicked.

Suggested change
if (e.target && (e.target as HTMLElement).tagName == "A") {
return;
let target = e.target as HTMLElement;
while (target) {
if (target.tagName === "A") {
return;
}
target = target.parentElement;

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@riknoll riknoll merged commit 625364a 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