JedWatson / JedWatson/react-select

react-select: 5.8.0 - Selected option only appears in input after focus is lost

Open
#5,940 0 comments 1 reaction 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 am currently developing a react (18) NextJS (14.2.5) application using Google Maps AutocompleteService. What I am experiencing is the selected value is not populating the input value unless the focus is lost on the element. I have verified that state is being updated.

const customStyles = {
  dropdownIndicator: (provided) => ({
    ...provided,
    display: 'none',
  }),
  indicatorSeparator: (provided) => ({
    ...provided,
    display: 'none',
  }),
  container: (provided) => ({
    ...provided,
    width: '100%',
    maxWidth: '600px',
    margin: '0 auto',
  }),
  input: (provided) => ({
    ...provided,
    width: '100%',
  }),
  singleValue: (provided) => ({
    ...provided,
    color: 'black', // Set the text color for selected value
  }),
  option: (provided) => ({
    ...provided,
    color: 'black', // Set the text color for options
  }),
  menu: (provided) => ({
    ...provided,
    width: '100%', // Ensure the menu width is responsive
  }),
  control: (provided, state) => ({
    ...provided,
    borderColor: state.isFocused ? 'blue' : 'gray', // Change border color on focus
    boxShadow: state.isFocused ? '0 0 0 1px blue' : 'none', // Add shadow on focus
  }),
};
      <Select
        inputValue={query}
        onInputChange={(newValue) => setQuery(newValue)}
        onChange={(selected) => {
          setQuery(selected ? selected.label : '');
          setSelectedOption(selected);
        }}
        options={options}
        placeholder="Search places..."
        className=""
        classNamePrefix="select"
        styles={customStyles}
        value={selectedOption}
        isClearable
      />

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

No repository file or test is identified in the report. Start by reproducing the controlled Select example with React 18 and NextJS 14.2.5, focusing on the interaction between inputValue, onInputChange, onChange, and value. Done means the selected option's label appears in the input immediately after selection without requiring focus to be lost.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.