Skip to main content

AutocompleteSingle

AutocompleteSingle component.

Default

<AutocompleteSingle
data={{
language: 'fr'
}}
dataKey="language"
column={{
options: [
{
label: 'Français',
value: 'fr'
},
{
label: 'English',
value: 'en'
},
{
label: 'Deutsche',
value: 'de'
}
]
}}
/>

With creation mode and clearable option

<AutocompleteSingle
data={{
language: 'fr'
}}
dataKey="language"
onChange={() => {
console.log('function called on change of option');
}}
column={{
disableClearable: false,
canCreate: true,
onCreate: () => {
console.log('function called on creation of a new option');
},
options: [
{
label: 'Français',
value: 'fr'
},
{
label: 'English',
value: 'en'
},
{
label: 'Deutsche',
value: 'de'
}
]
}}
/>

With creation mode and clearable option

<AutocompleteSingle
data={{
language: 'fr'
}}
dataKey="language"
onChange={() => {
console.log('function called on change of option');
}}
column={{
disableClearable: false,
canCreate: true,
onCreate: () => {
console.log('function called on creation of a new option');
},
options: [
{
label: 'Français',
value: 'fr'
},
{
label: 'English',
value: 'en'
},
{
label: 'Deutsche',
value: 'de'
}
]
}}
/>

With some other props from MUI AutoComplete (readOnly, fullWidth) :

<AutocompleteSingle
data={{
language: 'fr'
}}
readOnly={true}
fullWidth={true}
dataKey="language"
onChange={() => {
console.log('function called on change of option');
}}
column={{
disableClearable: false,
canCreate: true,
onCreate: () => {
console.log('function called on creation of a new option');
},
options: [
{
label: 'Français',
value: 'fr'
},
{
label: 'English',
value: 'en'
},
{
label: 'Deutsche',
value: 'de'
}
]
}}
/>

Props

NameTypeRequiredDefaultDescription
datastringyes---Describes the first option being displayed. Must contain an attribute with the same name as the dataKey
dataKeystringyes---Id that describes the list of options (ex: "language")
columnfunction/Arrayyes---Defines the list of options and how they should be handled by the component. See Column Props
onChangefunctionno(option)=>{}Function called when changing the current option
...otherPropsobjectno{}Other MUI AutoComplete props, such as readOnly, fullWidth, etc

Column Props

NameTypeRequiredDefaultDescription
canCreatebooleannofalseAllow or not the possibility to create a new option
disableClearablebooleannotrueAllow or not the possibility to clear the input field of the current option
onCreatefunctionno(inputValue, option)=>{}Function called when creating a new option