diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 880e022..0a84cc2 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -15,13 +15,20 @@ tallstackui_darkTheme() keeps it in localStorage ("dark-theme"), but only runs once Alpine starts, which would flash the light theme. Like the package, any value other than dark/light (true/false) means "system". + wire:navigate replaces the attributes with the server's, which + drops the class, so it is applied again on every page swap. --}} diff --git a/tests/Browser/ThemeToggleTest.php b/tests/Browser/ThemeToggleTest.php index 18dc3fb..9ea2a59 100644 --- a/tests/Browser/ThemeToggleTest.php +++ b/tests/Browser/ThemeToggleTest.php @@ -37,6 +37,24 @@ it('overrides a dark system theme', function () { ->assertScript('localStorage.getItem("dark-theme")', 'light'); }); +it('keeps the chosen theme when moving between pages with wire:navigate', function () { + $this->actingAs(User::factory()->admin()->create()); + + $page = visit(route('customers.index'))->inLightMode() + ->click(THEME_TOGGLE) + ->assertScript('document.documentElement.classList.contains("dark")', true); + + $page->click('Käyttäjät') + ->assertPathIs('/users') + ->assertScript('document.documentElement.classList.contains("dark")', true) + ->assertAttribute(THEME_TOGGLE, 'aria-pressed', 'true') + ->click('Asiakkaat') + ->assertPathIs('/customers') + ->assertScript('document.documentElement.classList.contains("dark")', true) + ->assertAttribute(THEME_TOGGLE, 'aria-pressed', 'true') + ->assertNoAccessibilityIssues(level: 2); +}); + it('is in the header for signed-in users and works with the keyboard', function () { $this->actingAs(User::factory()->create());