Khan / react-multi-select

A multiple select component for React
MIT License
183 stars 97 forks source link

feat: add onInputChange handler support #25

Closed TymchenkoOleksandr closed 5 years ago

TymchenkoOleksandr commented 6 years ago

@BrianGenisio , have a look, please

BrianGenisio commented 6 years ago

@TymchenkoOleksandr What is the use case for this? Why doesn't onSelectedChanged work?

TymchenkoOleksandr commented 6 years ago

@BrianGenisio - need to have input value to fetch options async using input value as a filter

TymchenkoOleksandr commented 6 years ago

currently the only way to access input value is to pass custom filterOptions function:

    filterOptionsFake(options: Array<Option>, inputValue: string): Array<Option> {
        this.setState(state => (inputValue === state.inputValue ? null : { inputValue }));
        return options;
    }

but this approach causes errors:

screen shot 2018-07-05 at 11 45 09 pm
BrianGenisio commented 6 years ago

Sorry about the late reply, you got me right before I left for vacation and I didn't communicate that. I'm still on vacation, but wanted to give some thoughts. I'm thinking of it from an interface perspective... exposing an event from the input feels like a leaky abstraction to me, and adds another property. What if options received an optional function instead? That function would return Options or a promise to the Options.

type Options = Array<Option>;
type OptionsFn = (filter: string) => Options | Promise<Options>;

type Props = {
    options: Options | OptionsFn,
    // the rest of the props
};

If we did this, it would probably make filterOptions obsolete, so I might want to deprecate that in a future, Major (semver) update.

Thoughts?

TymchenkoOleksandr commented 6 years ago

completely agree

BrianGenisio commented 6 years ago

@TymchenkoOleksandr Is this something you are working on? (updating your diff?) I'm just getting back from vacation, so it may be several days (as I catch up with work messages) before I can look at this, but I'm happy to if you're patient.

TymchenkoOleksandr commented 6 years ago

@BrianGenisio , currently i do not work on updating this diff