TextInput onKeyPress event hook
See original GitHub issueIs 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:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
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.