question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enter event on form wrapped input should not have e.preventDefault()

See original GitHub issue

First of all thanks @kentcdodds for authoring this library! Also thanks to everyone else who’s been helping Kent maintain this project ❤️.

  • downshift version: 1.28.0
  • node version: v8.1.3
  • yarn version: 1.2.1

What you did:

I type the string “black” (lowercase) into the form example in Downshift’s storybook - then hit ENTER.

What happened:

The form submission handler does not get called. However, my expectation is that the form submit handler gets called even though lowercase “black” isn’t a part of the list. This is important when building autocomplete for search services. When a user hits ENTER, I want to still be able to execute a search on lowercase “black”, even though it is not part of the list in the combobox:

screen shot 2018-02-13 at 11 16 09 am

Reproduction repository:

Reproducible in Downshift Storybook in the form example.

Problem description:

I think that a <form> submission handler should always be called on ENTER, even if the combo box list is open. I believe in the past, a <form> submission was not possible entirely, see #161.

Pull request #161 made it possible to submit the <form>, but not when the combobox list isOpen.

Suggested solution:

I am not sure I have an elegant solution. I am seeking the help of the community on this one. Please let me know if I got this all wrong and I’m simply not understanding the correct usage of Downshift.

A solution could be for Downshift to accept a prop isForm to Downshift. Then we will not call e.preventDefault when a user presses ENTER at all if the consumer of the component tells Downshift that a <form> wraps its <input>.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
kentcdoddscommented, Mar 5, 2018

Ok, great! It’s out and it’s actually downshift@1.29.0 (because this is a new feature 😅)

Thanks again!

2reactions
hzhucommented, Feb 22, 2018

I’m glad that the solution seems to work for you! I’d love a PR. If you’d prefer to wait for your co-worker to weigh in that’s fine with me.

Hi @kentcdodds, my schedule’s been hectic but I’ll try to submit a PR for review this weekend 😸 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

React prevent form submission when enter is pressed ...
You need to create a form handler that would prevent the default form action. The simplest implementation would be: <form onSubmit={e => {...
Read more >
Event.preventDefault() - Web APIs | MDN
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default ...
Read more >
How to Manage Browser Defaults with event. ...
This method prevents default actions that browsers make when an event is triggered. Here are some examples of default actions on webpages and ......
Read more >
Using Forms in React
Learn how to build forms with React, the difference between controlled and uncontrolled inputs, and which to use.
Read more >
Chapter 18 Forms and Form Fields
For some pages, the user is expected to want to interact with a form field immediately. JavaScript can be used to focus this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found