charmbracelet / charmbracelet/bubbles
feat: API for user to set value for the NoItems render [List]
- Dominant language
- Go
- Stars
- 8.9k
- Forks
- 457
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 5
Description
**Is your feature request related to a problem? Please describe.**
At the moment I couldn't find a way to remove the default `"No " + m.itemNamePlural + " found."` that is set when there are no visible items in the list.
**Describe the solution you'd like**
I would like an API in the model that I could do the following:
```go
l := list.New() // New list is created, I am omitting the params for simplicity
l.SetNoItemsPlaceHolder("Currently this list is empty") // Accepts a string
l.SetNoItemsPlaceHolder() // Possibility to leave blank
```
**Describe alternatives you've considered**
I tried something like this, but I couldn't get the title bar to show as well. Also it seems to much of a effort that could be easily done with an API 😄
```go
func (m Model) requestsView() string {
items := m.requests.VisibleItems()
if len(items) == 0 {
noItems := m.requests.Styles.NoItems.Render("Nothing found.")
return lipgloss.NewStyle().Height(m.height).Render(noItems)
}
return m.requests.View()
}
```
**Additional context**
This logic is already being done by the `func (m Model) populatedView() string` in the `list.go` line 1153. Should be simple to add a new `showNoItems bool` in the model for at least have the option to omit this
Contributor guide
Research direction
Start in list.go around Model.populatedView at line 1153, then inspect the model fields and existing Styles.NoItems behavior. Implement the requested way to customize or omit the empty-list text, and verify that both custom and blank values render correctly without losing the title bar.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100