Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Semantic UI React, how to build a tag input similar to Stack Overflow's?

I'm interested in building a Tag input feature like Stack Overflow where the feature set includes:

  1. Input field which has a autocomplete feature (takes user input, fetches results from the server and displays those results to the user for easy selection.
  2. Input field contains 1 or more selected items as tags.
  3. Suggestions outside of the input which when clicked have the results added to the input field.

Screenshots from Stack Overflow:

enter image description here enter image description here

I'm using Semantic-UI-React and notice there is a search component which could work: https://react.semantic-ui.com/modules/search

It does not appear that this Semantic-UI-React search component allows for adding more than one result or adding results via a method outside of the input. Am I missing something?

Should I use Semantic UI for this feature or will I need to build this entirely from scratch in my React app?

like image 223
AnApprentice Avatar asked Oct 18 '25 16:10

AnApprentice


2 Answers

It's not properly highlighted in the react semantic-ui dropdown documentation but the allowAdditions field will enable tagging capabilities:

<Dropdown search selection multiple allowAdditions />
like image 143
Dan Ochiana Avatar answered Oct 21 '25 05:10

Dan Ochiana


You need to add the onAddItem prop to update the options list. In here, I did this:

<Dropdown placeholder='Select Friend' fluid search selection multiple allowAdditions onAddItem={(event, data) => friendOptions.push({key: data.value, text: data.value, value: data.value})} options={friendOptions} />

And now you can add items to the dropdown list.

like image 43
C-likethis123 Avatar answered Oct 21 '25 07:10

C-likethis123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!