0

I'm new to using React and material-table and am trying to sort out how to initiate search after the user presses Enter. I've been able to find the debounceInterval option, but the API I am using to search remote data currently does not return partial matches so I'd like the user to press "Enter" when they want the search to start.

Using monitorEvents($0) I can see that there is a keydown Event on the element input.MuiInputBase-input.MuiInput-input.MuiInputBase-inputAdornedStart.MuiInputBase-inputAdornedEnd but I'm not sure how to add an event listener here or is there is an option to specify which event.target.value to use to start the search. The material-table Search code is here: https://github.com/mbrn/material-table/blob/master/src/components/m-table-toolbar.js

Any help would be greatly appreciated.

4

2 回答 2

2

例子:

<TextField
  onKeyPress={(ev) => {
   console.log(`Pressed keyCode ${ev.key}`);
    if (ev.key === 'Enter') {
  // Do code here
     ev.preventDefault();
    }
  }}
  />
于 2019-09-24T03:31:18.440 回答
0

能不能详细解释一下...

于 2019-09-24T04:10:39.970 回答