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

fix(tile): ClickableTile should navigate on keypress #14945

Merged

Conversation

tay1orjones
Copy link
Member

Reported on slack

I can't find a good reason as to why the keydown handler would need to call preventDefault(). I think it was added by accident during the functional refactor, #9721

Changelog

Changed

  • No longer call evt.preventDefault() in the keydown handler

Testing / Reviewing

  • In the ClickableTile story: focus the tile, press enter or space, the clickabletile should navigate. It previously would not navigate.
  • This behavior should match what happens on click of the clickabletile.

@tay1orjones tay1orjones requested a review from a team as a code owner October 19, 2023 14:05
@tay1orjones tay1orjones self-assigned this Oct 19, 2023
@tay1orjones tay1orjones added this to the 2023 Q4 milestone Oct 19, 2023
@tay1orjones tay1orjones added type: bug 🐛 severity: 2 https://ibm.biz/carbon-severity severity: 3 https://ibm.biz/carbon-severity and removed severity: 2 https://ibm.biz/carbon-severity labels Oct 19, 2023
@netlify
Copy link

netlify bot commented Oct 19, 2023

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit cbe5ac6
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/653137b47f7b0f0008ec22bb
😎 Deploy Preview https://deploy-preview-14945--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Oct 19, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit cbe5ac6
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/653137b4835b23000898af13
😎 Deploy Preview https://deploy-preview-14945--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

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

LGTM 👍 ✅

Copy link
Contributor

@andreancardona andreancardona left a comment

Choose a reason for hiding this comment

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

tested & looks good!

@andreancardona andreancardona added this pull request to the merge queue Oct 19, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 19, 2023
@tw15egan tw15egan added this pull request to the merge queue Oct 19, 2023
Merged via the queue into carbon-design-system:main with commit e41a4db Oct 19, 2023
22 checks passed
@alewitt2
Copy link
Contributor

I know this issue is already merged, but i just ran into a related issue and i think i may have insight as to why preventDefault() was defined and also a another bug in the code

  function handleOnKeyDown(evt: KeyboardEvent) {
    evt?.persist?.();
    if (matches(evt, [keys.Enter, keys.Space])) {
      setIsSelected(!isSelected);
      onKeyDown(evt);
    }
    onKeyDown(evt);
  }

If a user defines their own callback for onKeyDown, then there is a good chance they want to control what happens when any key is pressed (including enter and space). That said.. the way the code was and is written, doesnt really solve the that problem for the user. Something like the following would be required:

  function handleOnKeyDown(evt: KeyboardEvent) {
    evt?.persist?.();
    if (matches(evt, [keys.Enter, keys.Space])) {
      setIsSelected(!isSelected);
      if (user defined onKeyDown) { // would need some logic to understand when a user defined the callback or not
        evt.preventDefault();
        onKeyDown(evt);
      }
    } else { // this else is necessary to prevent the callback being called twice when enter/space keys are pressed.
      onKeyDown(evt);
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants