isOptionDisabled does not make text grey
I want to set option disabled (as in tutorial make it unselectable and grey), but it only gets unselectable. Setting options
const opts = {
...
isOptionDisabled: this.isOptionDisabled,
...
};
isOptionDisabled (option) {
return option.isDisabled;
}
Getting choices
let res = json['choices'].map(opt => ({
label: opt.text,
value: opt.id,
isDisabled: opt.is_disabled
}));
And it all looks like this (as you can see, all choices look the same):

Is it bug or am I doing something wrong?
React-select's version is 2.1.0
For future reference, the Issue Tracker is meant for reporting bugs with react-select. You should post questions, such as this, to StackOverflow.
I think the issue you have is that your isOptionDisabled method is not bound right. It appears as though you render your Select from a class (although it's hard to tell without more code). If you refactored your class method like this:
isOptionDisabled = (option) => option.isDisabled;
Or, alternatively if you handled the binding directly at the prop level
<Select {...otherProps}
isOptionDisabled={this.isOptionDisabled.bind(this)} />
That should take care of your issue. I setup a quick codesandbox to verify this. I have a json file with a list of songs, and added the following song:
{
"_id": 24,
"artist": "The Monkees",
"title": "Last Train To Clarkesville",
"genre": ["pop"],
"isDisabled": true
}
Then I setup my class
import React, { Component } from "react";
import Select from "react-select";
import songs from "./songs.json";
export default class MySelect extends Component {
isOptionDisabled = option => option.isDisabled;
getOptionLabel = option => option.title;
getOptionValue = option => option._id;
render() {
return (
<Select
options={songs}
getOptionLabel={this.getOptionLabel}
getOptionValue={this.getOptionValue}
isOptionDisabled={this.isOptionDisabled}
/>
);
}
}
And got the output exactly as you expected.
