onBlur doesn't work in custom component
See original GitHub issuehi, a thousand apologies for post this here, but this crash my mind
i don’t understand why onBlur doesn’t work
what i expect: when i choose some checkboxes with options and click whatever at the page - select will collapse
what i get: select collabes only when i click on arrow
pls help me and sorry for my poor english
you can check code here - https://codesandbox.io/s/elegant-mestorf-7rvl8
and i past it here
import ReactDOM from "react-dom";
import Select, { components } from "react-select";
const styles = {
option: styles => ({
...styles,
backgroundColor: "#ffff",
color: "black"
})
};
const Option = props => (
<components.Option {...props}>
<input type="checkbox" checked={props.isSelected} readOnly />
<label>{props.data.label}</label>
</components.Option>
);
const ValueContainer = ({ children, selectProps, ...props }) => {
console.log(selectProps);
const { getValue, hasValue } = props;
const countSelectedVal = getValue().length;
if (!hasValue) {
return (
<components.ValueContainer {...props}>
{children}
</components.ValueContainer>
);
}
return (
<components.ValueContainer {...props}>
{`${selectProps.messages.orderPageAnySelectPreText}: ${countSelectedVal}`}
</components.ValueContainer>
);
};
const OrderSelectMulti = ({ options, ...props }) => {
const components = { ValueContainer, Option };
const messages = {
orderPageAnySelectPreText: "Selected"
};
return (
<Select
styles={styles}
isMulti
messages={messages}
components={components}
hideSelectedOptions={false}
options={[
{ value: "Status1", label: "Status1" },
{ value: "Status2", label: "Status2" },
{ value: "Status3", label: "Status3" }
]}
placeholder="BlaBla"
{...props}
/>
);
};
const rootElement = document.getElementById("root");
ReactDOM.render(<OrderSelectMulti />, rootElement);
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:12 (3 by maintainers)
Top Results From Across the Web
why I can't get my onChange/onBlur handler work on custom ...
You need to pass along the event handlers as props all the way to the input component. As it is, your input has...
Read more >react hook form onblur not working - You.com | The AI Search ...
In your code, the form mode is onBlur . it means the validation is triggered on blur event (unfocus the input). When you...
Read more >SyntheticEvent - React
The onBlur event handler is called when focus has left the element (or left some element inside of it). For example, it's called...
Read more >Window: blur event - Web APIs | MDN
The blur event fires when an element has lost focus. The opposite of blur is focus . This event is not cancelable and...
Read more >Advanced - React Select
React-select is committed to providing a custom experience to all users and relies heavily ... These two methods sit as callable methods on...
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
I was facing the same issue you were, where you could only close the menu by clicking the arrow. I got around this with a deceptively simple workaround: render the children of the ValueContainer, but just style them to have opacity: 0. This will maintain the original ValueContainer’s functionality, but allow you to render whatever you want in the ValueContainer. Here’s my code:
I have the same issue. blur is not working and remain the blue border style on the element ‘sometimes’ after selecting an option if I have customized the component. e.g. When the
error
prop changed from ‘true’ to ‘false’ in the following function.