shabeeb ck
shabeeb ck

Reputation: 131

How to make pre-select a value on material ui Autocomplete component (react)?

I want to make a value pre-selected on the drop-down list on this material UI Autocomplete component, it is on the update details page, how do I make it? here is my code below

<FormControl variant="outlined" fullWidth>
            <Autocomplete
              id="combo-box-demo"
              options={props.options}
              getOptionLabel={option => option.label}
              onChange={(event, newValue) => {
                if (props.selectedValue) props.selectedValue(newValue);
                if (props.getvalue) props.getvalue(newValue.id);
              }}
              renderInput={params => (
                <TextField
                  {...params}
                  size="small"
                  variant="outlined"
                  className="formField"
                  name={props.name}
                  inputRef={props.register}
                />
              )}
            />
          </FormControl>

Upvotes: 0

Views: 550

Answers (1)

Priyanka Panjabi
Priyanka Panjabi

Reputation: 441

Add placeholder to TextField like :

 <TextField
              {...params}
              placeholder ={ "The value that you want to set as preselected" }
              size="small"
              variant="outlined"
              className="formField"
              name={props.name}
              inputRef={props.register}
            />

Upvotes: 1

Related Questions