Skip to content

Conversation

@knanao
Copy link
Contributor

@knanao knanao commented Nov 21, 2025

Fixes: #4369

Summary

Fix unreadable text in selected list items when theme uses background: "none"

Details

When a theme sets "background": "none", the background color resolves to fully transparent. Previously, selected list items used theme.background as the foreground color, making the text invisible. This PR adds a helper that returns a contrasting color (black or white) based on the luminance of theme.

Before:

Screenshot 2025-11-21 at 16 33 19 Screenshot 2025-11-21 at 16 33 30

After:

Screenshot 2025-11-21 at 16 36 04 Screenshot 2025-11-21 at 16 36 11

@ariane-emory
Copy link
Contributor

Minutes before you submitted this, I'd just submitted an alternate solution by adding an optional selectedListItemText theme element to allow users to explicitly choose a colour for selected list items: #4572

Maybe we should combine our approaches, allowing either my explicit colour selection via selectedListItemText or your automatic selection when an explicit selectedListItemText is nor present in the theme?

@knanao
Copy link
Contributor Author

knanao commented Nov 21, 2025

@ariane-emory
Oh, sorry, I didn’t notice that. I agree your solution, and making this configurable is good.

Maybe we should combine our approaches, allowing either my explicit colour selection via selectedListItemText or your automatic selection when an explicit selectedListItemText is not present in the theme?

👍
Then I’m going to close this PR, and I’m also happy to make some changes to your PR on my side, so please let me know if needed.

@ariane-emory
Copy link
Contributor

No need to apologize! Tackling the problem from both ends and allowing either automatic colour selection or explicit selection is probably more robust than doing either in isolation. I'll try merging your branch into mine and see how it works.

@knanao
Copy link
Contributor Author

knanao commented Nov 21, 2025

@ariane-emory
Yeah, that's better. Thank you!

@knanao
Copy link
Contributor Author

knanao commented Nov 21, 2025

merge with #4572.

@knanao knanao closed this Nov 21, 2025
@knanao knanao reopened this Nov 22, 2025
Comment on lines +794 to +804
customBorderChars={
theme.background.a != 0
? {
...EmptyBorder,
horizontal: "▀",
}
: {
...EmptyBorder,
horizontal: " ",
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the changes added in 23ea8ba, a black line is displayed when backgroundElement is transparent. OpenTUI might not recognize borderColor when it is set to transparent and instead displays it in the default black.
Screenshot 2025-11-22 at 21 33 16

@knanao
Copy link
Contributor Author

knanao commented Nov 23, 2025

Close this, since #4572 has been merged,

@knanao knanao closed this Nov 23, 2025
@knanao knanao deleted the fix/list-selection-fg branch November 23, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unreadable text on selected list when "background": "none"

2 participants