JedWatson / JedWatson/react-select

When using a controlled Select with a custom ValueContainer the select won't open

Open
#6,063 0 comments 3 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

Hello Everyone, first and foremost Kudos on this package, it is pretty amazing.

I am having a problem when I use react-select with a custom ValueContainer and a controlled select, the Select will not open, well.

I think is triggering both onMenuOpen and onMenuClose almost at the same time

I was able to reproduce the error on Playcode so here it is https://playcode.io/2514348

I will also copy the code here

import React, { useState } from 'react';
import Select from 'react-select';
import { components } from 'react-select';

export const flavourOptions = [
  { value: { name: 'vanilla' }, label: 'Vanilla' },
  { value: { name: 'chocolate' }, label: 'Chocolate' },
  { value: { name: 'strawberry' }, label: 'Strawberry' },
  { value: { name: 'saltedcaramel' }, label: 'SaltedCaramel' },
];

export const customValueContainer = ({ children, ...props }) => {
  return (
    <components.ValueContainer {...props}>{children}</components.ValueContainer>
  );
};

export function App(props) {
  const [open, setOpen] = useState(false);
  const [open1, setOpen1] = useState(false);

  return (
    <div className='App'>
      <h2>First Select work properly</h2>
      <Select
        isClearable
        isMulti
        menuIsOpen={open}
        placeholder='label'
        role='list'
        closeMenuOnSelect={false}
        hideSelectedOptions={false}
        ariaLabel='dropdown-input'
        isClearable
        onMenuClose={e => {
          setOpen(false);
        }}
        onMenuOpen={e => {
          setOpen(true);
        }}
        options={flavourOptions}
      />
      <h2>Second also works!</h2>
      <Select
        isSearchable
        placeholder='label'
        role='list'
        ref={undefined}
        closeMenuOnSelect={false}
        hideSelectedOptions={false}
        ariaLabel='dropdown-input'
        components={{
          ValueContainer: props => {
            return customValueContainer(props);
          },
        }}
        options={flavourOptions}
      />
      <h2>Third one has an error </h2>
      <Select
        onMenuClose={e => {
          setOpen1(false);
        }}
        onMenuOpen={e => {
          setOpen1(true);
        }}
        menuIsOpen={open1}
        isSearchable
        placeholder='label'
        role='list'
        ref={undefined}
        closeMenuOnSelect={false}
        hideSelectedOptions={false}
        ariaLabel='dropdown-input'
        components={{
          ValueContainer: props => {
            return customValueContainer(props);
          },
        }}
        options={flavourOptions}
      />
    </div>
  );
}


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

Run the linked Playcode reproduction and compare the controlled Select with and without the custom ValueContainer. Trace the controlled Select path involving menuIsOpen, onMenuOpen, and onMenuClose. Done means the third Select opens reliably without immediately closing, while the reported callbacks retain the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.