Skip to content

Commit

Permalink
Show warning when ui.dark_mode breaks Tailwind (#3994)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
falkoschindler authored Nov 18, 2024
1 parent 24ee85a commit 7eaaded
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nicegui/elements/dark_mode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional

from .. import core, helpers
from ..events import Handler, ValueChangeEventArguments
from .mixins.value_element import ValueElement

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

# HACK: this is a temporary warning to inform users about issue #3753
if core.app.is_started:
self._check_for_issue_3753()
else:
core.app.on_startup(self._check_for_issue_3753)

def _check_for_issue_3753(self) -> None:
if self.client.page.resolve_dark() is None and core.app.config.tailwind:
helpers.warn_once(
'`ui.dark_mode` is not supported on pages with `dark=None` while running with `tailwind=True` (the default). '
'See https://github.com/zauberzeug/nicegui/issues/3753 for more information.'
)

def enable(self) -> None:
"""Enable dark mode."""
self.value = True
Expand Down

0 comments on commit 7eaaded

Please sign in to comment.