Material-UI Call function when clearing autocomplete textfield

295 views Asked by At

I'm using a material-ui autocomplete text field to filter a list and I want to be able to repopulate the list to its full form when the text is deleted and enter is hit. As far as I can tell the onNewRequest property is only called if there is text in the text field. Is there a way to call a function when pressing enter with no text?

1

There are 1 answers

0
Jeff McCloud On

You can use the onUpdateInput event of the AutoComplete component to test if the text field is empty:

<AutoComplete
  ...
  onUpdateInput={
    (value) => {
      if (value.length === 0) {
        console.log('Refresh the list here');
      }
    }
  }
/>