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

Help Needed: Material Tailwind Select Component Requires Selecting Option Twice to Display Correct Value #696

Open
Halazv2 opened this issue Jun 4, 2024 · 5 comments

Comments

@Halazv2
Copy link

Halazv2 commented Jun 4, 2024

I'm facing an issue with a Select component in my react project. When I fetch options from an API and display them in the select component, the selected value only displays correctly if I select the option twice, also the initially selected value fetched from the backend does not show up.

Screenshot 2024-06-04 at 22 06 16

Code:

       <Select
        variant="standard"
        label="Current Living Address"
        name="current_address"
        value={values.current_address}
        onChange={(val) => 
            handleChange({
              target: {
                name: "current_address",
                value: val
              }
            })
          }
        onBlur={handleBlur}
        error={Boolean(errors.current_address && touched.current_address)}
      >
        {addresses.length > 0 && (
          addresses.map((address) => (
            <Option key={address.id} value={address.id} className="capitalize">
              {address.number} - {address.street}
            </Option>
          ))
        )}
      </Select>
      {errors.current_address && touched.current_address && (
        <ErrorText error={errors.current_address} />
      )}
@Nishant-Pathak
Copy link

+1 facing the same issue.

@Cmejia49
Copy link

Cmejia49 commented Jul 7, 2024

+1 same issue

1 similar comment
@patiwatpanda
Copy link

+1 same issue

@alexmady
Copy link

+1 same

@r1y4h
Copy link

r1y4h commented Aug 20, 2024

Select component in controlled state will not work properly if the options are not available yet on initial render. Workaround is by making sure the options are readily available first, before rendering the Select component.

Or you can add a default option as suggested by their bot support:
image

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

6 participants