JedWatson / JedWatson/react-select

Enter key submitting form when menu open but showing no options

Open
#3,823 13 comments 9 reactions 0 assignees View on GitHub

@diogobas is already working on this.

Since Feb 24, 2020.

  • #3945 by @diogobas — open
issue/bug-confirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Within a <form onSubmit={}> form that uses an onSubmit handler and a regular old <button type="submit">, the enter key is submitting the form despite the react-select menu being open. This seems to happen when there are no options to display in the list.

image

Have created a quick demo here:

https://codesandbox.io/s/react-codesandboxer-example-i6bwn

Steps to reproduce:

  1. Type any non-existent colour in the select and ensure you are seeing the "No options" message.
  2. Hit enter, see the alert that the form has been submitted.

Is this intended behaviour?

Thanks :)

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 by reproducing the issue in the linked CodeSandbox: type a value with no matching options and press Enter inside the form. Review open pull request #3945 for the current direction, then confirm the intended behavior for Enter when the menu shows “No options”; done means that behavior is resolved and verified without unintended form submission.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.