tbleckert / react-select-search

⚡️ Lightweight select component for React
https://react-select-search.vercel.app
MIT License
678 stars 147 forks source link

search not working in groups #199

Open rjworks opened 3 years ago

rjworks commented 3 years ago

fuzzy search.js:

// eslint-disable-next-line import/no-extraneous-dependencies
import Fuse from 'fuse.js';

export default function fuzzySearch(options) {
    const fuse = new Fuse(options, {
        keys: ['name', 'value', 'items.name', 'items.value'],
        threshold: 0.3,
    });

    console.log(fuse)

    return (value) => {
        if (!value.length) {
            return options;
        }

        return fuse.search(value);
    };
}

SelectSearch

 <SelectSearch
                    options={options}
                    value={value}
                    onChange={setValue}
                    search={true}
                    emptyMessage="Not found"
                    placeholder="Try COSC 111"
                    printOptions="always"
                    autoFocus={true}
                    autoComplete={'off'}
                    filterOptions={fuzzySearch}
                />

It only filters the group name, and not the items within the group

Antonji-py commented 3 years ago

have the same issue, here is something similar but does not solve our problem https://github.com/tbleckert/react-select-search/issues/181

markyoxall commented 3 years ago

I eventually went with react-select as this did everything.