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

Trying to detect what is the users system preference #117

Open
AdamBD opened this issue Jan 8, 2022 · 3 comments
Open

Trying to detect what is the users system preference #117

AdamBD opened this issue Jan 8, 2022 · 3 comments
Labels
question Further information is requested

Comments

@AdamBD
Copy link

AdamBD commented Jan 8, 2022

I am using the following line to set the users color mode preference:
this.$nuxt.$colorMode.preference = this.checked ? "dark" : "light";

As I understand it this should set the default preference of the user. When requesting the preference of the user I am then getting
this.$nuxt.$colorMode.preference = 'system'

I assume that here system is representing that this module will check for the stored cookie on the users browser and take the literal string value from there.

When trying to check what that value is I am still getting system (However when printing the entire ColorMode object I am actually getting 'dark'.

What is the correct way to understand what is the VALUE of the system preference?

image

@AdamBD AdamBD added the question Further information is requested label Jan 8, 2022
@nklsw
Copy link

nklsw commented Mar 4, 2022

I encounter the same issue (using v3.0.1). Any updates?

@FayKn
Copy link

FayKn commented Oct 7, 2022

Yes, preference is just what the user set as what they prefer (handy for a mode switcher).

colormode value = the device's preference if colormode preference = system

@greetfish
Copy link

greetfish commented Nov 23, 2022

mounted() {
    setTimeout(() => {
      console.log(this.$colorMode.value);
    }, 200);
    console.log(this.$colorMode);
  }

i get the right result: light
must ensure it run on client side

and you can get preference by media query :
console.log('is dark ?:' + window.matchMedia('(prefers-color-scheme: dark)').matches);

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

No branches or pull requests

4 participants