charmbracelet / bubbletea

A powerful little TUI framework 🏗

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filter search not working in list-simple example

souvikinator opened this issue · comments

After running the example list-simple/main.go I noticed that the search function is not getting triggered.

I see the FilterValue() is also defined just like in other list examples.

Not sure if this is the default behavior or some issue.

Edit

l.SetFilteringEnabled(true) setting this to true enables the search but now the issue is it shows nothing in the search like so:

issue-bubble

FilterValue() must be defined in order to satisfy the Item interface defined here. For the filter to work properly, you'll have to update the list model if you receive a list.filterMatchesMsg tea command. Since this is a private struct, you have to catch the cmd in the default case.

Hi! So the list example was actually intended to have filtering disabled, but it looks like we accidentally left some of the filtering hooks in. We’ll remove it to keep the simple example simple.

That said, here is the simple list example with filtering enabled and here is the diff with the necessary changes. Basically, you just need to make sure the enter doesn't select an item while filtering and then you just need to make sure all messages pass through list’s Update function so filter matching messages will be processed.

On that note (and to your point, @jon4hz) list.filterMatchesMsg should probably be exposed so people can match on that message.


Edit: whoops, I totally missed your PR there, @jon4hz. That’s also a great example of how to do it.

Hey there! thanks for clarifying. So I was trying to update the list contents in View rather than Update. Now it's working, thanks for pointing out :)

@meowgorithm if you want filtered disabled in the simple-list example I'll close my PR. Exposing list.filterMatchesMsg is imo a cool idea.

Can't reproduce this anymore, the filter tooltip isn't showing up in list-simple. Thanks for the ticket, closing!