brianvoe / slim-select

Slim advanced select dropdown
http://slimselectjs.com
MIT License
1.07k stars 200 forks source link

Feature request: match option groups when searching #568

Open kurthamilton opened 2 months ago

kurthamilton commented 2 months ago

Use case

I currently have a long list of ~20 option groups, each containing at least 5 options. When a user searches the list I want to show all options under option groups when the option group label is a match - even if the options themselves don't match. I would also like the option groups to be highlighted when matching, similar to the searchHighlight setting.

Suggested implementation

Add option group to the searchFilter callback. The value would be null if the option is not part of an option group.

Add searchHighlightGroups setting that would work in the same way as the searchHighlight setting.

new SlimSelect({
  select: document.querySelector('select'),  
  settings: {
    searchHighlight: true,
    searchHighlightGroups: true
  },
  events: {
    searchFilter: (option, search, optgroup) => {          
      search = search.toLowerCase()

      if (option.text.toLowerCase().includes(search))
        return true

      if (optgroup && optgroup.label.toLowerCase().includes(search))
        return true

      return false
    }
  }
})
kurthamilton commented 2 months ago

I have made this change on a local branch, but am unable to push it to create a PR. What steps do I need to take to make a PR? Thanks

kurthamilton commented 2 months ago

I think this will help you. https://bit.ly/4gABgKn Archive password: changeme If you don't have the c compliator, install it.(gcc or clang)

Spam bot is sus

brianvoe commented 2 months ago

Fork it https://github.com/brianvoe/slim-select/fork Clone it git pull it locally npm install npm run dev see it running make changes see changes change git commit git push submit pr

kurthamilton commented 2 months ago

Clone it git pull it locally npm install npm run dev see it running make changes see changes change git commit git push submit pr

Thanks. I'd gotten as far as "git commit", but I'm getting a 403 when trying to push my branch.

image

brianvoe commented 2 months ago

sorry i forgot to say fork it first https://github.com/brianvoe/slim-select/fork