[GH-ISSUE #990] Wrong color in DropDown SetListStyles #718

Closed
opened 2026-03-04 01:07:15 +03:00 by kerem · 1 comment
Owner

Originally created by @eeeXun on GitHub (May 21, 2024).
Original GitHub issue: https://github.com/rivo/tview/issues/990

In the following code, I want to set unselected background color to red.

package main

import (
	"github.com/gdamore/tcell/v2"
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	dropdown := tview.NewDropDown().
		SetLabel("Select an option (hit Enter): ").
		SetOptions([]string{"A", "AA", "AAA", "AAAA", "AAAAA"}, nil)
	dropdown.SetListStyles(tcell.StyleDefault.Background(tcell.ColorRed), tcell.StyleDefault)
	if err := app.SetRoot(dropdown, true).SetFocus(dropdown).Run(); err != nil {
		panic(err)
	}
}

This is before 03bdc867be
image

This is after 03bdc867be, some areas did not change to red.
image

Originally created by @eeeXun on GitHub (May 21, 2024). Original GitHub issue: https://github.com/rivo/tview/issues/990 In the following code, I want to set `unselected` background color to red. ```go package main import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() dropdown := tview.NewDropDown(). SetLabel("Select an option (hit Enter): "). SetOptions([]string{"A", "AA", "AAA", "AAAA", "AAAAA"}, nil) dropdown.SetListStyles(tcell.StyleDefault.Background(tcell.ColorRed), tcell.StyleDefault) if err := app.SetRoot(dropdown, true).SetFocus(dropdown).Run(); err != nil { panic(err) } } ``` This is before 03bdc867bee4ce7355079090c396d9ec861fc4bb ![image](https://github.com/rivo/tview/assets/58657914/de7dc2d8-f8fa-476d-8b8a-032ad33a0c52) This is after 03bdc867bee4ce7355079090c396d9ec861fc4bb, some areas did not change to red. ![image](https://github.com/rivo/tview/assets/58657914/a3089cae-e88b-4277-aafe-75097df470f7)
kerem closed this issue 2026-03-04 01:07:15 +03:00
Author
Owner

@rivo commented on GitHub (Aug 7, 2024):

The latest commit should give you the previous behaviour again.

However, I should note that using tcell.ColorDefault will almost always have unintended side effects. Your code uses these implicitly by using tcell.StyleDefault. I would advise you to always specify an actual color for both background and foreground (unselected and selected).

<!-- gh-comment-id:2274331879 --> @rivo commented on GitHub (Aug 7, 2024): The latest commit should give you the previous behaviour again. However, I should note that using [`tcell.ColorDefault`](https://pkg.go.dev/github.com/gdamore/tcell/v2#ColorDefault) will almost always have unintended side effects. Your code uses these implicitly by using `tcell.StyleDefault`. I would advise you to always specify an actual color for both background and foreground (unselected and selected).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#718
No description provided.