Sharlaan / material-ui-superselectfield

multiselection autocomplete dropdown component for Material-UI
https://sharlaan.github.io/material-ui-superselectfield
MIT License
266 stars 92 forks source link

Extending AutoComplete Options #157

Closed music-mind closed 6 years ago

music-mind commented 6 years ago

I have been playing around with the AutoComplete, and was wondering if there is a way to use the Autocomplete to add new items. The onAutoCompleteTyping only exposes the search value; how can I use it to add a new item / listen for keyPress events?

music-mind commented 6 years ago

Modified SuperSelectField to do so in a fork.

Sharlaan commented 6 years ago

erm adding items is not the responsibility of an Autocomplete.

The onAutoCompleteTyping only exposes the search value; how can I use it to add a new item / listen for keyPress events?

You'll have to implement that in a wrapper above superselectfield, catching the keypress events from onAutoCompleteTyping, then store that in that wrapper state. Then add some button so user can "ADD" the stored value, which will actually be merged into SSF's children. SSF should then display that new value in its options.

SSF is just a display component, with some borderline features like filtering, but that's it.

music-mind commented 6 years ago

Yep, I was just wondering if it would be better to make it default. For example, I exposed the onEnter to catch Enter inside onKeyPress to achieve what I wanted. Maybe exposing onKeyPress could add more functionality.

Sharlaan commented 6 years ago

onAutoCompleteTyping IS onKeyPress

music-mind commented 6 years ago

onAutoCompleteTyping only gives the string though, not the event, so how would that work? (AutoCompleteText => {...do something})

Sharlaan commented 6 years ago

Try it with a console log you should see the result after each keypress, is not what you are searching for ?

Sharlaan commented 6 years ago

closing, since nothing new