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.

TextInput onKeyPress event hook

See original GitHub issue

Is your feature request related to a problem? Please describe. We’re currently building custom Merchant Center applications using components from this library. One of the things we’re trying to implement is a search input field. We’d like to use TextInput, but we don’t want to search on every onChange event, but only when the user presses a key (in this case Enter).

Describe the solution you’d like Add an optional hook for onKeyPress to the TextInput component.

Describe alternatives you’ve considered Create our own input component with the correct styling.

Additional context I’m not the most experienced React developer, so perhaps I missed a way to accomplish this with the existing components.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
davidweteringscommented, Jul 3, 2019

Thanks for the suggestion @montezume . We actually implemented it exactly like this just a few moments ago!

Since there’s already a ticket for passing the other props, I’m gonna close this one. Thanks again for the quick response!

1reaction
montezumecommented, Jul 3, 2019

Hi,

Thanks for creating the issue. Have you considered just wrapping your input in a form and putting your search logic in the forms onSubmit? I created a codesandbox to show this. This way you don’t need to use onKeyPress and watch for a specific key press.

Does this solve your problem?

Sidenote: this issue goes well with #706. Once we do this refactor, you would be able to pass any props you need to the input itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use React onKeyPress (Example Code Included)
To handle key presses in React, we use onKeyPress. It is passed as an attribute in <input> elements, and can be used to...
Read more >
useState hook not working inside onKeyPress handler in ...
It looks like you need to bind the function to the onKeyPress event handler. You can easily accomplish this by using an arrow...
Read more >
onkeypress Event - W3Schools
The onkeypress event occurs when the user presses a key (on the keyboard). Tip: The order of events related to the onkeypress event:...
Read more >
Integrate text input: "Press enter" keyboard event
Integrate text input: "Press enter" keyboard event ... In the code override, we can hook into onAccept in the same way as onTap...
Read more >
How to Use the Enter Key Event Handler on a React-Bootstrap ...
In this guide, you'll learn about keyboard events and how to submit a form using the enter key event handler for the input...
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