Skip to content
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

Pressing [ENTER] on any input inside <form> element will toggle Downshift #315

Closed
philipyoungg opened this issue Jan 29, 2018 · 12 comments
Closed

Comments

@philipyoungg
Copy link
Contributor

  • downshift version: 1.16.1
  • npm (or yarn) version: npm 5.5.1

Relevant code or config

const App = () => (
  <form>
    <input type='text'/>
    <Downshift>
      {({isOpen, getButtonProps}) => (
        <div>
          <button {...getButtonProps()}>
            ay
          </button>
          {isOpen &&
            <div>
              Yo wassup
            </div>
          }
        </div>
      )}
    </Downshift>
  </form>
);

What you did: Pressing [ENTER] on any input inside

element

What happened: It will toggle Downshift content

What do I expect: It won't toggle the Downshift component when pressing [ENTER] inside form element.

Reproduction repository: https://codesandbox.io/s/pwn92r9plx

Suggested solution: I haven't checked on the "why" yet. Adding here first so I won't forget it. :)

@serg-plusplus
Copy link

@philipyoungg, It's not Downshift fault 🤨
https://codesandbox.io/s/wnm9zwqw0w

@serg-plusplus
Copy link

Pressing [ENTER] on any input element calls 'submit' event on form; If Button[type="submit"(by default)] is present in the form - before 'submit' event it will call 'click' event on this button.
How to Fix: <button type="button">... in your Form. 🤗

@philipyoungg
Copy link
Contributor Author

Whoa didn’t know that before submit—form will click the button with type=submit.

Thanks @NoTruth!

@philipyoungg
Copy link
Contributor Author

Closing as this is not relevant anymore 😁

@kentcdodds
Copy link
Member

My co-worker has this same problem. Maybe we should explicitly return the type as button from getButtonProps unless it's overridden. I don't think anyone would want the button to submit the form.

@philipyoungg
Copy link
Contributor Author

@kentcdodds agreed.

@serg-plusplus
Copy link

Will it be appropriate to create a brunch with upcoming Button changes?
I also want to implement Button_focus() after reset

@kentcdodds
Copy link
Member

I also want to implement Button_focus() after reset

I don't think that's a common enough use case to make that the default. More common to want to focus the input I think...

Who wants to make a PR to add type: 'button' to this object?

https://github.com/paypal/downshift/blob/10c69241c9525b9866a42b9f9cbc7f76365bc0e6/src/downshift.js#L554-L561

@kentcdodds
Copy link
Member

Actually, this is a great first-timers-only issue... So I'm going to prepare it later today and only allow first-time OSS contributors to submit a PR for it :)

@kentcdodds
Copy link
Member

kentcdodds commented Jan 29, 2018

🆕🐥☝ First Timers Only
This issue is reserved for people who never contributed to Open Source before. We know that the process of creating a pull request is the biggest barrier for new contributors. This issue is for you 💝

About First Timers Only.

🤔 What you will need to know
Nothing. This issue is meant to welcome you to Open Source :) We are happy to walk you trough the process.

📋 Step by Step

  • 🙋 Claim this issue: Comment below
    Please 🙏 only claim if you want to start working on it within a day.
  • 👓 Please review our Code of Conduct
    In a nutshell: be patient and actively kind with us 😊
  • 📝 Update the file downshift.js in the this repo by following the steps in the CONTRIBUTING.md guide. Please add type: 'button' above this line.
  • 🔀 Start a Pull Request. Include the text closes #315 in the description.
    If this is your first, welcome 🎉 😄 Here is a great tutorial on how to send a pull request using the terminal.
  • 🏁 Done 👍 Wait patiently for someone to review your PR and provide feedback :)

🤔❓ Questions? Comment here :)

@xutopia
Copy link
Contributor

xutopia commented Jan 29, 2018

Hi, I would like to claim this issue please.

@xutopia xutopia mentioned this issue Jan 29, 2018
4 tasks
@kentcdodds
Copy link
Member

Congratulations @xutopia!

Rendez pushed a commit to Rendez/downshift that referenced this issue Sep 30, 2018
* add type button to the return object getButtonProps

* added myself to the contributor list

Closes downshift-js#315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants