Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialValue prop not working? #36

Open
julianeden opened this issue Feb 8, 2023 · 3 comments
Open

initialValue prop not working? #36

julianeden opened this issue Feb 8, 2023 · 3 comments

Comments

@julianeden
Copy link

julianeden commented Feb 8, 2023

Hi, I have initialValue set and it's not using it.

        <Select
            initialValue={maxPlayers}
            options={[1, 2, 3, 4, 5, 6, 7, 8]}
            onOptionChange={setMaxPlayers}
            getOptionValue={opt => opt}
            getOptionLabel={opt => opt}
          />

I even hard-coded it to initialValue={2} without success. Am I doing something wrong?

@julianeden
Copy link
Author

julianeden commented Feb 8, 2023

Okay, by examining the source code I found that this prop is passed through a call to normalizeValue, and that if it isn't an array or a plain object it returns an empty array here. Not sure if this is a bug or intended, but it seems like a bug since the documentation says type: any for this prop.

Putting the passed prop value in an array resolves the issue, but this seems like it might merit a fix. Since initialValue is rather integral to many form inputs I'm somewhat surprised to find this bug at all. Can't imagine how nobody ran into it before.

@julianeden
Copy link
Author

julianeden commented Feb 8, 2023

I found a second issue with this, although this time I'm less sure what can be done about it. Because the dropdown has an initialValue prop but no value prop, programmatically updating the state value the dropdown is associated with doesn't update the dropdown itself. It can only be updated by the user manually changing it.

So if I want to change the dropdown's value in response to a separate user action, there doesn't seem to be a way to do so. Is there a way to do this?

Edit: I found that I can do this using a ref and the prescribed API, although this feels a bit hacky.

@natBizitza
Copy link

I miss the value prop. In my case, the ref.current.setValue is in useEffect and depends on a prop (an array of strings). When I set isMulti=true I get an inifity loop.

I tried to set intialValue or defaultValue and the input is not refreshed, but the component state is updated according to the Chrome Dev Tools.
Screenshot 2024-04-09 at 12 11 06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants