Skip to content

Conversation

@diogobas
Copy link

@diogobas diogobas commented Feb 24, 2020

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.

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.

Enter key submitting form when menu open but showing no options #3823

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2020

💥 No Changeset

Latest commit: 76452c3

Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂

If these changes should be published to npm, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 24, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 76452c3:

Sandbox Source
react-codesandboxer-example Configuration
react-codesandboxer-example PR

@bladey bladey added pr/needs-review PRs that need to be reviewed to determine outcome uncertain and removed pr/needs-review PRs that need to be reviewed to determine outcome labels May 26, 2020
@bladey bladey added pr/needs-review PRs that need to be reviewed to determine outcome enhancement and removed uncertain labels Jun 4, 2020
@goremykin
Copy link

Faced the same issue. Any updates?

@bladey bladey added pr/enhancement PRs that are specifically enhancing the project and removed category/enhancement labels Jun 24, 2020
@ebonow ebonow linked an issue Feb 7, 2021 that may be closed by this pull request
Copy link
Collaborator

@ebonow ebonow left a comment

Choose a reason for hiding this comment

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

@DiogoBastos,

I could be overlooking some things, but I have questions regarding some of the implementation here. I could be over simplifying this, but it seems like replacing

if (!focusedOption) return;

with

if (!focusedOption) break;

would fix this, so unsure why there is extra logic to identify if the target is a button or to preventDefault on all Enter clicks which are not selecting an option. This is purely assumptive on my part so looking to better understand the use-case here.

const targetIsButton = event.target && event.target.type === 'button';

if (targetIsButton) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of checking for event.target.type === 'button'

break;
}
return;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change return to break here? This seems like a breaking change should a user decide to use react-select with a textarea.

@usamamashkoor
Copy link

Did you find any solution for this?

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

Labels

pr/enhancement PRs that are specifically enhancing the project pr/needs-review PRs that need to be reviewed to determine outcome

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enter key submitting form when menu open but showing no options

5 participants