material-tailwind icon indicating copy to clipboard operation
material-tailwind copied to clipboard

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

Open Halazv2 opened this issue 2 years ago • 5 comments

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} />
      )}

Halazv2 avatar Jun 04 '24 21:06 Halazv2

+1 facing the same issue.

Nishant-Pathak avatar Jun 17 '24 10:06 Nishant-Pathak

+1 same issue

Cmejia49 avatar Jul 07 '24 11:07 Cmejia49

+1 same issue

patiwatpanda avatar Jul 15 '24 07:07 patiwatpanda

+1 same

alexmady avatar Jul 16 '24 19:07 alexmady

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

r1y4h avatar Aug 20 '24 16:08 r1y4h