Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event id not been dispatch #5

Open
mylastore opened this issue Jan 7, 2022 · 1 comment
Open

Event id not been dispatch #5

mylastore opened this issue Jan 7, 2022 · 1 comment

Comments

@mylastore
Copy link

<DarkMode on:change={(e) => { console.log(e.detail); // "dark" | "light" }} />

The event is not dispatched only after a full browser reloads then I see the console log.
Using this repo with the latest SvelteKit

@metonym
Copy link
Owner

metonym commented Jan 7, 2022

When I use this component with SvelteKit, I see the change event being dispatched when the page mounts, and also whenever I update the theme.

Is this what you would expect? To help further, it would be useful if you could provide a minimal repro.


  1. Load the page: "dark" is logged
  2. Click the button --> "light" is logged
<script>
  import DarkMode from "svelte-dark-mode";

  let theme;

  $: switchTheme = theme === "dark" ? "light" : "dark";

  $: if (typeof document !== "undefined") {
    document.body.className = theme;
  }
</script>

<DarkMode
  bind:theme
  on:change={(e) => {
    console.log(e.detail); // "dark" | "light"
  }}
/>

<h1>This is {theme} mode.</h1>
<p>Change the theme and reload the page.</p>

<button on:click={() => (theme = switchTheme)}>
  Switch to {switchTheme} mode
</button>

<style>
  :global(.dark) {
    background: #032f62;
    color: #f1f8ff;
  }
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants