Skip to content

Conversation

@malwilley
Copy link
Member

@malwilley malwilley commented Apr 30, 2025

Currently we have custom logic in the DropdownMenu component which handles link items. The react-aria library should already be handling this, but we configured things a bit differently than react-aria expected which prevented it. This PR removes the custom behavior and provides a href for react-aria to use.

I'm hoping that this change fixes some bugs I've seen on mobile devices. On iOS especially, taps on dropdown link items have no effect.

Summary of changes:

  • Add href to the dropdown item state if to or externalHref is passed
  • Remove custom logic handling keyboard selection of a link item
  • Moves the dropdown item props from the container li element to the "inner item" (which is an anchor tag in the case of links)
  • Fixes tests that looked for link roles instead of menuitemradio

@malwilley malwilley requested review from a team as code owners April 30, 2025 23:22
@malwilley malwilley requested review from a team and removed request for a team April 30, 2025 23:23
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 30, 2025
@malwilley malwilley requested a review from a team April 30, 2025 23:23
&:focus,
&:focus-visible {
color: ${getTextColor};
box-shadow: none;
Copy link
Member Author

Choose a reason for hiding this comment

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

These overrides are necessary because InnerWrap now gets focus instead of MenuItemWrap

Copy link
Collaborator

Choose a reason for hiding this comment

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

please make sure you do the same changes in the chonk version if they are needed there as well:

export const ChonkInnerWrap = chonkStyled('div', {

});

// JSDOM throws an error on navigation to random urls
expect(errorSpy).toHaveBeenCalledTimes(1);
Copy link
Member Author

Choose a reason for hiding this comment

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

There is already another test in this file which expects this error to be thrown, this already appeared to be an issue

&:focus,
&:focus-visible {
color: ${getTextColor};
box-shadow: none;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please make sure you do the same changes in the chonk version if they are needed there as well:

export const ChonkInnerWrap = chonkStyled('div', {

hoverProps,
keyboardProps,
makeInnerWrapProps(),
{ref: innerWrapRef, 'data-test-id': key}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is that data-test-id needed? As far as I can see, all tests use a role-based selector (which is the preferred solution anyway)

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately there are quite a few tests using the dropdown component which do rely on the data-test-id 😞

I agree that using roles is better (and the vast majority do that), but I didn't want to convert those tests in this PR

@malwilley malwilley merged commit acb9b1a into master May 1, 2025
41 checks passed
@malwilley malwilley deleted the malwilley/fix/dropdown-menu-links branch May 1, 2025 21:41
@sentry-io
Copy link

sentry-io bot commented May 2, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: �[2mexpect(�[22m�[31mjest.fn()�[39m�[2m).�[22mtoHaveBeenCalledWith�[2m(�[22m�[32m...expected�[39m�[2m)�[22m ?(index.spec.tsx) View Issue
  • ‼️ Error: �[2mexpect(�[22m�[31mreceived�[39m�[2m).�[22mtoEqual�[2m(�[22m�[32mexpected�[39m�[2m) // deep equality�[22m Object.?(tagDetailsDrawerContent.spec.tsx) View Issue

Did you find this useful? React with a 👍 or 👎

andrewshie-sentry pushed a commit that referenced this pull request May 12, 2025
Currently we have custom logic in the DropdownMenu component which
handles link items. The react-aria library should already be handling
this, but we configured things a bit differently than react-aria
expected which prevented it. This PR removes the custom behavior and
provides a `href` for react-aria to use.

I'm hoping that this change fixes some bugs I've seen on mobile devices.
On iOS especially, taps on dropdown link items have no effect.

Summary of changes:

- Add `href` to the dropdown item state if `to` or `externalHref` is
passed
- Remove custom logic handling keyboard selection of a link item
- Moves the dropdown item props from the container `li` element to the
"inner item" (which is an anchor tag in the case of links)
- Fixes tests that looked for `link` roles instead of `menuitemradio`
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants