JedWatson / JedWatson/react-select

Elements within custom Menu components are not interactable on touch devices

Open
#6,071 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Custom Menu components that contain elements outside of the MenuList can't be interacted with on touch devices. A valid use case for this is building menus with buttons/tooltips/links/checkboxes as a header/footer elements above/below the list of options.

This occurs because the touch handlers check whether the event target is a child of the MenuList ref, and if not, blurs the input (thereby closing the menu). For this to work as expected, the handler should also check whether the element is a child of the Menu ref.

For example:

const CustomMenu = (props) => {
  return (
    <components.Menu {...props}>
      <div>Header</div> // <- Can't click anything inside on touch
      {props.children}
      <div>Footer</div> // <- Can't click anything inside on touch
    </components.Menu>
  );
};

<Select
  ...
  components={{ Menu: CustomMenu }}
/>

A Codesandbox demonstrating this issue can be found here: https://codesandbox.io/p/sandbox/modest-cdn-xz7kls. There is a workaround for this issue, which is to add a touchEnd listener on the element that prevents propagation of the event, i.e:

const CustomMenu = (props) => {
  return (
    <components.Menu {...props}>
      <div onTouchEnd={e => e.stopPropagation()}>Header</div>
      {props.children}
      <div onTouchEnd={e => e.stopPropagation()}>Footer</div>
    </components.Menu>
  );
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Menu component's touch handlers and the MenuList and Menu refs described in the issue, then reproduce the behavior with the linked CodeSandbox. Trace why touches outside MenuList close the menu, and verify completion by confirming that header and footer controls inside a custom Menu remain interactable on touch devices.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.