Key press issue with custom Control
See original GitHub issueI’m using react-select v3.1 and I’m experiencing some very odd behavior, not sure if I’m doing something wrong or if there is a bug.
Scenario : I am making a custom select and I want to create a custom Control that the user can type in to perform searches.
Expected behavior: User can type normally in the custom Control to search for an item to select
Current behavior: Custom Control is made but the typing experience is not working correctly. Some key presses aren’t being triggered in the custom control such as backspace, space-bar and delete. Here is some code that illustrates what I am currently doing and the result (this is just for illustration):
import React from "react";
import Select from "react-select";
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
];
const MyCustomControl = () => {
return <input />;
};
class App extends React.Component {
state = {
selectedOption: null,
};
handleChange = (selectedOption) => {
this.setState({ selectedOption }, () =>
console.log(`Option selected:`, this.state.selectedOption)
);
};
render() {
const { selectedOption } = this.state;
return (
<Select
value={selectedOption}
onChange={this.handleChange}
isSearchable={true}
options={options}
components={{
Control: MyCustomControl,
}}
/>
);
}
}
export default App;
Issue Analytics
- State:
- Created 3 years ago
- Comments:12
Top Results From Across the Web
WinForms Custom Control: Why doesn't the arrow key raise ...
This is a dummy custom control. The entire source is at the bottom. If I place the control on an empty form (no...
Read more >Custom user control key events problem [SOLVED] - Daniweb
I didn't figure out exactly how to do what I had wanted, but I did achieve the end result for my program. I...
Read more >Control key acts as if it is stuck periodically - Super User
Generic fix for this generic issue: press stuck key or Ctrl + Alt + Del , Esc . · Press both ctrl at...
Read more >Resolve Hotkeys or Volume control keys not working on ...
This issue may occur if there is a problem with the USB connection on your computer. This issue can also occur if a...
Read more >If your Mac doesn't respond to key presses - Apple Support
If this solves the problem, you may need to take your keyboard in for service. If no keys work on your Mac notebook...
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
Wow, thanks so much @ebonow! This works! Really appreciate the help and speedy replies
@jbyomuhangi Fortunately, this is not an issue. Full explanation and working demo below
First, an explanation of the impact of line 20
props.children[0]
of theControl
is theValueContainer
which contains theDummyInput
DummyInput
is the element responsible for receiving focus when the Select is clicked onBut, what about the button?
console.log(document.activeElement)
reveals that the focus is on the body, so the keyDown events are no longer captured by the Select.isFocused
state onFocus and onBlurWorking demo
I hope this answers all of your questions. It wasn’t entirely intuitive for me either, especially realizing that the button wasn’t maintaining focus. I will close this issue as everything does appear to be functional, but happy to work through any other questions you have. As before, I can reopen this if necessary.