Can't block OnKeyEvent from happening on Select
Are you making a feature request?
Provide as much information as possible about your requested feature. Here are a few questions you may consider answering:
-
What's your use case? Trying to extend react-select to have custom Chips inside that turn into editable text fields/ inputs when you double click on them.
-
What interface do you have in mind? (What new properties or methods do you think might be helpful?) OnKeyDown should bypass any action if it's a function the user set. Or something inbetween these lines. For instance I'm trying to make ArrowRight and ArrowLeft bypass the React-Select KeyHandler that can be seen at https://github.com/JedWatson/react-select/blob/c31ef9496ea91ca905e03ef3fcdac21b864464d5/src/Select.js#L1142-L1149
-
Can you point to similar functionality with any existing libraries or components? (Working demos can be helpful.) For the intended result just open up Gmail and try to send a new email and select/type people/emails and click on them.
I've tried stopping the event from propagating to stop react-select from doing any actions since you have a return condition for this. But this also makes the cursor not change character since the event was stopped altogether.
Any feedback on what my next steps should be will be greatly appreciated. Whether I should use something else, or if I'm over complicating things.
My goal is to have a input for chips with autocomplete that mimics material, just like gmail's email for example.
I can't copy everything I have on my src to codepen so here's a small example that shows react select rendering inputs with dummy data, try using arrow keys to navigate inbetween each one and see that the event does not move the cursor but goes to previous or next focus of the list. It's also logging to console onKey
@kwskii, I think the authors of this library have provided incredible customization tools to allow you to accomplish this; do them a favor, close this and try stack overflow.
Why would I?
As I've seen and said through their own source code, the arrow left and arrow right key events block every other events that these keys might've triggered and as such. In my case, where the items inside the component are inputs, I cannot use the arrow keys to navigate between the input characters.
If you're saying there's a way of blocking this then why not just say it :)
As I think this is a bug/or just something the devs didn't plan for I am making it under a feature request. I don't see why I should close this and try stack overflow (which by the way I asked a question there 2 months ago and nobody has responded yet) :)
@kwskii Using ev.stopPropagation() in the KeyDown-Event on the input in MultiValue allows me to use the arrow keys to move the text cursor.
@flipch ,
Here is a codesandbox using the recommendation that @Rall3n suggested.
It appears to be working here as expected. Please note that the render of the MultiValue was also moved to a new component in the codesandbox to follow best practices and improve performance.
I will be marking this as closed given that there is a solution, but please feel free to follow up with any questions.