Skip to content

Commit 7eaaded

Browse files
Show warning when ui.dark_mode breaks Tailwind (#3994)
As discussed in #3753, `ui.dark_mode` can break Tailwind styling if used on a page with `dark=None` ```py @ui.page('/', dark=None) def page(): ui.dark_mode(True) ui.label('This should be bordered').classes('border') ``` or with `ui.run(dark=None)`. This PR shows a warning in this situation. I won't link it with the issue because this isn't a proper fix.
1 parent 24ee85a commit 7eaaded

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

nicegui/elements/dark_mode.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional
22

3+
from .. import core, helpers
34
from ..events import Handler, ValueChangeEventArguments
45
from .mixins.value_element import ValueElement
56

@@ -20,6 +21,19 @@ def __init__(self, value: Optional[bool] = False, *, on_change: Optional[Handler
2021
"""
2122
super().__init__(value=value, on_value_change=on_change)
2223

24+
# HACK: this is a temporary warning to inform users about issue #3753
25+
if core.app.is_started:
26+
self._check_for_issue_3753()
27+
else:
28+
core.app.on_startup(self._check_for_issue_3753)
29+
30+
def _check_for_issue_3753(self) -> None:
31+
if self.client.page.resolve_dark() is None and core.app.config.tailwind:
32+
helpers.warn_once(
33+
'`ui.dark_mode` is not supported on pages with `dark=None` while running with `tailwind=True` (the default). '
34+
'See https://github.com/zauberzeug/nicegui/issues/3753 for more information.'
35+
)
36+
2337
def enable(self) -> None:
2438
"""Enable dark mode."""
2539
self.value = True

0 commit comments

Comments
 (0)