creativetimofficial / material-tailwind

@material-tailwind is an easy-to-use components library for Tailwind CSS and Material Design.
https://material-tailwind.com/
MIT License
3.51k stars 306 forks source link

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

Open Halazv2 opened 3 weeks ago

Halazv2 commented 3 weeks ago

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 commented 1 week ago

+1 facing the same issue.