Niklas Fondberg
Niklas Fondberg

Reputation: 113

React Material-UI autocomplete show Add button when there are no results

I'm trying to find a way to show an "Add" button when there are no results. Is there a way to be able to get an event when no options where found? I see that there is an noOptionsText prop but I can't seem to find a way to get triggered when there are no results. Does anyone know if this is possible?

I'm using Material-UI v5-beta and React 17.

Upvotes: 1

Views: 1481

Answers (2)

Dani
Dani

Reputation: 4186

You can play around with this and detect when you have no elements to show and return whatever you need:

renderOption={(props, option) => <li {...props}>{option.name}</li>}

Upvotes: 0

Vladi Feldman
Vladi Feldman

Reputation: 952

What you're looking for is the Creatable freesolo mode of Autocomplete. it's in their documentation.

Here's a link to the codesandbox as well.

Upvotes: 2

Related Questions