react-select with selectable group labels

Viewed 2072

Is there a way to have the group labels in react-select selectable? I want to be able to do a search, have all of the relevant items to show in addition to their group label, and be able to click and select the group label (which has it's own ID value).

1 Answers

Here is exactly what you are looking for. https://github.com/JedWatson/react-select/pull/2659#issuecomment-450700209

loadOptions = (value) => {
    return this.getSuggestions(value).then(
      rsp => {
        const suggestions = this.filterGroupedSuggestions(rsp.data)
        const creatable = {
          label: `Search "${value}"`,
          value: value,
          group: 'search'
        }
        return [creatable, ...suggestions]
      }
    )
  }

Related