JedWatson / JedWatson/react-select

AsyncSelect: defaultOptions should use current input value on first call

Open
#5,714 1 comment 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

When using <AsyncSelect> we can have the options loaded by calling loadOptions when the input is first opened by setting defaultOptions to true.

But on that first open the inputValue doesn't seem to be getting passed to the loadOptions call. This means that if the user was typing in the input, and we've saved their partial input, when they re-focus the input the options presented don't match their input.

Example codesandbox: https://codesandbox.io/s/codesandboxer-example-forked-mwmy98

Example video:
https://github.com/JedWatson/react-select/assets/1711350/6b7b12df-cce9-4b9c-978c-21dbf82f7082

Here I type "re" and the filtered options are loaded correctly. I blur the input, leaving "re" as the input value. When I re-focus it, the options presented are the defaults before I typed anything, not those I had for the "re" input previously.

I think that defaultOptions: true should be calling loadOptions with the current value of inputValue every time the input is re-selected, so that the user is presented with the valid options for their current input.

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 at the AsyncSelect handling for defaultOptions and loadOptions, using the linked CodeSandbox to reproduce the behavior when an input is re-selected. Confirm that loading on re-focus uses the current inputValue, and verify that the displayed options match the saved partial input.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.