Skip to content

fix(dropdown-menu): Remove custom link behavior #90713

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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
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
Contributor

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', {

);

await userEvent.click(screen.getByRole('button', {name: 'Menu'}));
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Item One'}));
await waitFor(() => {
expect(screen.queryByRole('menuitemradio')).not.toBeInTheDocument();
});

// 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

color: ${getTextColor};
box-shadow: none;
Copy link
Contributor

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
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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