I am using react-select as a searchable drop-down in my react app. I am referring this link https://github.com/JedWatson/react-select.
In the drop-down options structure, it needs label
and value
keys in the respective object in options
.
My problem is, I dont have any label
or value
in my options
data.
I am having different keys altogether.
I want the drop-down to be searched by different key tab
.
My code for drop-down:
<Select
name="selectSubTag"
id="selectSubTag"
value={this.state.selectedFilter.subTag}
options={this.state.jobSubTags}
onChange={this.setSubTag}
placeholder="Select Sub Tag"/>
Where my options
data looks like below:
this.state.jobSubTags = [
{tab:"tabName 1",tabValue:1},
{tab:"tabName 2",tabValue:2},
{tab:"tabName 3",tabValue:3},
]
and now I want the data to be searched by 'tab' key in the dropdown.
To fetch the selected value from the select element, you can use the onChange event handler prop. Just like the input or textarea elements, you can use the onChange event handler to get the value from the event object. Now, make this select input element controlled by using the state to pass the value.
ButtonGroup supports checkbox type selection in which multiple button can be selected. This can be achieved by adding input element along with id attribute with its corresponding label along with htmlFor attribute inside the target element.
You can use getOptionLabel
and getOptionValue
:
<Select
name="selectSubTag"
id="selectSubTag"
value={this.state.selectedFilter.subTag}
options={this.state.jobSubTags}
getOptionLabel ={(option)=>option.tab}
getOptionValue ={(option)=>option.tabValue}
onChange={this.setSubTag}
placeholder="Select Sub Tag"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With