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

useMediaQuery is not working as expected #1591

Closed
7 tasks done
jd-solanki opened this issue May 12, 2022 · 6 comments
Closed
7 tasks done

useMediaQuery is not working as expected #1591

jd-solanki opened this issue May 12, 2022 · 6 comments

Comments

@jd-solanki
Copy link
Contributor

Describe the bug

I am using usePreferredColorScheme composable but I wasn't returning the value I wanted so I dig down and tried to use useMediaQuery.

I noticed that useMediaQuery('(prefers-color-scheme: dark)') is returning false. However, if I run below code, I get DARK MODE... logged to console.

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
  console.log('DARK MODE...')

Full code

const colorScheme = usePreferredColorScheme()
console.log('colorScheme.value :>> ', colorScheme.value)

const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)')
console.log('isPreferredDark :>> ', isPreferredDark.value)

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
  console.log('DARK MODE...')

Output
Screenshot 2022-05-12 at 12 39 09 PM

Reproduction

https://stackblitz.com/edit/vitejs-vite-dlmmn4?file=src/App.vue

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 1.07 GB / 7.71 GB
    Container: Yes
    Shell: 0.12.1 - /home/jd/.xonsh/.venv/bin/xonsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 101.0.4951.54
  npmPackages:
    @vueuse/core: ^8.2.6 => 8.4.2 
    vue: ^3.2.33 => 3.2.33

Used Package Manager

yarn

Validations

@alokVishu
Copy link

Yes, I am also feeling the same issue.
+1

@stale
Copy link

stale bot commented Sep 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 14, 2022
@jd-solanki
Copy link
Contributor Author

Keep it open

@stale stale bot removed the stale label Sep 14, 2022
@GODLiangCY
Copy link
Contributor

It should be solved in #2178 . How about trying again with the newest version of VueUse?

@stale
Copy link

stale bot commented Dec 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 30, 2022
@jd-solanki
Copy link
Contributor Author

It is working as expected after trying posted code with the latest version.

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

3 participants