简体   繁体   中英

Autocomplete MaterialUI - How can I set a default value in Grouped autocomplete

I am using Autocomplete grouped component? I want that a default value already selected when component loads or refresh.

Code is below code

<Autocomplete
    id="grouped-demo"
    className={'input-dropdown'}
    options={options.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter))}
    groupBy={(option) => option.firstLetter}
    getOptionLabel={(option) => option.title}
    onChange={this.linkDropdownChange}
    renderInput={(params) => <TextField {...params} label="grouped Collection" variant="outlined" />}
/>

As per the documentation, you got two options

Controllable states The component has two states that can be controlled:

the "value" state with the value/onChange props combination. This state represents the value selected by the user, for instance when pressing Enter. the "input value" state with the inputValue/onInputChange props combination. This state represents the value displayed in the textbox.

Done!!!!!

Autocomplete grouped component uses defaultValue as object not a string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM