JedWatson / JedWatson/react-select

When using ValueContainer as a custom component, if children is not rendered, the menu does not close when clicking outside

Open
#5,982 6 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
Dominant language
TypeScript
Stars
28k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

I'm using the react-select 5.8.3 version, and I'm using components properties to extend the ValueContainer to custom components, and I'm writing this after finding an issue.

When using a multi-select, I implemented a conditional statement as shown below to customize the appearance of the ValueContainer as a custom component.

// my custom ValueContainer.tsx
function ValueContainer(props: ValueContainerProps<OptionBase[] | OptionBase>) {
  const {
    children,
    selectProps: { value, isMulti },
  } = props;

  if (!isMulti) {
    return <components.ValueContainer {...props}>{children}</components.ValueContainer>;
  }

  const valueLength = Array.isArray(value) ? value.length : 0;
  const text = valueLength > 0 ? {{MY_CUSTOM_TEXT}} : children; // If isMulti is true and there is at least one selected value, it renders custom text.

  return <components.ValueContainer {...props}>{text}</components.ValueContainer>; // clicking outside the Select’s DOM does not close the menu
}

It seems that when children is not rendered in the ValueContainer as per the condition mentioned above, the menu close does not work when clicking outside.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the custom ValueContainer.tsx example and reproduce the behavior using react-select 5.8.3, focusing on the multi-select path where children is replaced. Then trace the Select outside-click handling and ValueContainer integration; done means the menu closes when clicking outside even when custom text is rendered.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.