saadeghi / theme-change

Change CSS theme with toggle, buttons or select using CSS custom properties and localStorage
https://codepen.io/saadeghi/pen/OJypbNM
MIT License
1.31k stars 48 forks source link

Support for Livewire 3 wire:navigate #44

Open rustynail1984 opened 10 months ago

rustynail1984 commented 10 months ago

Toggle is not working after navigate in a Livewire 3 app using wire:navigate.. you need to use livewire:navigated instead of DOMContentLoaded

See here https://livewire.laravel.com/docs/navigate#dont-rely-on-domcontentloaded

joshleblanc commented 2 weeks ago

@rustynail1984 Replace themeChange() with

addEventListener('livewired:navigated', () => {
  themeChange(false);
});

This also applies to anyone using turbo:

addEventListener("turbo:load", () => {
    themeChange(false);
})