Repository navigation
Closed
Description
While implementing custom menu with option closeMenuOnSelect=false click outside do not close menu. Issue is probably cause lose of input focus.
- Open menu and click outside, menu close as expected
- Open menu, clear all items and click outside, menu close as expected
- Open menu, select option and click outside menu is still open
- Open menu, clear any option and click outside menu is still open
const props = {
...
components: {
Menu: ({options: renderedOptions, selectOption, selectProps, innerProps}) => (
<DropdownMenu className={`${classNamePrefix}__menu`} {...innerProps}>
{
renderedOptions && renderedOptions.length > 0
? (renderedOptions.map((option) => (
<DropdownItem
key={option[VALUE_KEY]}
tag="div"
onClick={() => selectOption(option)}
className={classnames(`${classNamePrefix}__menu-option`, {
[`${classNamePrefix}__menu-option_is-selected`]: selectProps.value && (
Array.isArray(selectProps.value)
? selectProps.value.some((selectedValue) => selectedValue[VALUE_KEY] === option[VALUE_KEY])
: selectProps.value[VALUE_KEY] === option[VALUE_KEY]),
})}
role="option"
>
{option.name}
</DropdownItem>
)))
: <span className={classnames(`${classNamePrefix}__no-options`)}>{msg.noOptions}</span>
}
</DropdownMenu>
),
ValueContainer: ({children, ...restValueContainerProps}) => (
<DropdownToggle className={`${classNamePrefix}__flip-toggle`} tag="div">
<components.ValueContainer {...restValueContainerProps}>
{children}
</components.ValueContainer>
</DropdownToggle>
),
MultiValueContainer: ({children, ...restValueContainerProps}) => (
<DropdownToggle className={`${classNamePrefix}__flip-toggle`} tag="div">
<components.MultiValueContainer {...restValueContainerProps}>
{children}
</components.MultiValueContainer>
</DropdownToggle>
),
IndicatorSeparator: () => <span />,
}
}
note: Im using reactstrap coponents becasuse their handle menu floping when its needed
Reacted by Sean Golob, Sasha Khamkov, Abhijeet Ahuja, Kevin Law, Carmen, Patrick Ullrich, Daisuke Itan, Ben Nyberg, Karan, oksana-barylo and 2 more
Metadata
Metadata
Assignees
Labels
No labels
Activity
j-funk commentedon Jan 18, 2019
I think this is related to #2597
clickblipclick commentedon Dec 26, 2019
Here's a minimal reproduction of this issue:
https://codesandbox.io/s/ecstatic-chatelet-nupqk?fontsize=14&hidenavigation=1&theme=dark
It seems to be the case that using the provided
ValueContainercomponent along withcloseMenuOnSelect={false}causes the menu to not close on click outside. This is also an issue with V3.clickblipclick commentedon Dec 26, 2019
And I think I just figured out why. You can't define your replacement component directly on the components prop object like this:
You have to define the custom component elsewhere outside the render like so:
Why? I assume because there is some side-effect event listener being added, on recreating the component on every render causes that not to work. (Just a guess).
todesstoss commentedon Feb 24, 2020
Faced the same issue.
In this case it's no possible to provide custom props to this custom component
UPD:
for someone else facing same issue, custom props can be passed on Select element and accessed via
props.selectPropsdeniswvieira commentedon Mar 11, 2020
Wow
Nice catch!
Anyway it would be nice not to have caution defining components outside the scope.
tswes commentedon Mar 18, 2020
@todesstoss thank you for this; solved the issue for me.
bladey commentedon Jun 3, 2020
Hi all,
In an effort to sustain the
react-selectproject going forward, we're closing issues that appear to have been resolved via community comments or issues that are now redundant based on their age.However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you, and we'll re-open it if necessary.
manisha-seclogic commentedon Jul 15, 2021
so what is the solution if we want to keep both
please help
achorein commentedon Jun 3, 2022
After several tries, i came to a hacking solution :
(no need of external component)
faizantroon commentedon Aug 4, 2023
Today i have come across with this issue and i resolved it by moving my custom components outside of React functional component, Basically you can't define functional component within another functional component because it cause re renders and it will not close the dropdown
nynevi commentedon Jan 5, 2024
for people who is still scratching their heads around why it does not work after extracting components to be outside our functional component's return or class component's render method; wrap the components in a useMemo rather than extracting it to be outside. an example:
please note that if dependencies of the useMemo change, you'll still run into the same issue so the dependencies should not contain props that change depending on the menu (or the input in my case)
danielgamboar commentedon Jan 17, 2024
@faizantroon
MAGIC!