nicegui: Tailwind text colors set via ".classes" selectively don't work for buttons
Description
Trying to specify text color via “.classes” selector works well for labels and other elements but doesn’t work for buttons when the color has a specified hue as can be seen on examples below:
Example code:
from nicegui import ui
def main():
ui.label('Label color works').classes("text-red-400")
ui.button("Button color doesn't work").classes("text-red-400")
ui.button("Unless it's pure color").classes("text-red")
ui.run()
if __name__ in {"__main__", "__mp_main__"}:
main()
Result:
More examples using the styling function in the documentation, just to make sure it’s not an issue with my environment
For a label the “text-red-400” tailwind class works:
For a button, the same class doesn’t work:
Although this way it works:
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (6 by maintainers)
Commits related to this issue
- add note about Tailwind vs. Quasar (fixes #1821) — committed to artreven/nicegui by falkoschindler 3 years ago
I feel your pain @anatoli26! We’ve always had problems with coloring buttons. The
colorparameter should make it easier, but somehow it even adds to the confusion.There’s been a similar problem with padding in
ui.card. Quasar’s CSS rules made it very difficult to built NiceGUI’s layout system on top. In PR #3444 we finally solved it by manipulating Quasar’s CSS via JavaScript: https://github.com/zauberzeug/nicegui/blob/637e79585638daf2a2b02890b20105af5c4718fa/nicegui/static/nicegui.js#L438-L445Maybe there’s a similar solution for buttons. We should check if there are any negative side effects, but maybe we can remove Quasar’s “!” important marker from this specific rule.
For reference, in #4415 we see an excerpt of quasar.css and its
!importantmadness. There I refused to modify Quasar’s default behavior. But if we better understand the implications, it might be a viable solution - maybe for NiceGUI 3.0 due to breaking changes. I’m struggling to find an explanation for why they chose to do it this way.In https://github.com/quasarframework/quasar/issues/5566 we see how Quasar encourages to set custom colors: Define a new “text-” or “bg-” class and apply it to the UI element. This doesn’t seem viable for NiceGUI because every new color would need to add new CSS definitions.
The
ui.buttonelement applies a few color classes as part of its default instantiation. Specifically thetext-whiteclass is giving you trouble here:You can override these by instantiating it with
color=None: