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

MatchMedia.matches support #921

Closed
belgattitude opened this issue May 14, 2023 · 2 comments · Fixed by #925
Closed

MatchMedia.matches support #921

belgattitude opened this issue May 14, 2023 · 2 comments · Fixed by #925
Assignees
Labels
enhancement New feature or request

Comments

@belgattitude
Copy link

belgattitude commented May 14, 2023

Is your feature request related to a problem? Please describe.

Would be great to provide window.matchMedia().matches support.

Describe the solution you'd like

Currently happy-dom isn't able to work with

const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';

Currently on latest version 9.18.3 it produces

TypeError: Cannot read properties of undefined (reading 'matches')

      12 |
      13 | const getDefaultTheme = () => {
    > 14 |   const browserTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';

Describe alternatives you've considered

N/A

Additional context

I'm currently trying to get a faster ci in the strapi repo: one iteration consists of trying to move from js-dom to happy-dom.

See strapi/strapi#16713 (comment)

@belgattitude belgattitude added the enhancement New feature or request label May 14, 2023
@capricorn86 capricorn86 self-assigned this May 15, 2023
capricorn86 added a commit that referenced this issue May 18, 2023
…eries. Adds support for CSS measurment values to Window.matchMedia() and Window.getComputedStyle(). Adds support for the "height" property to CSSStyleDeclaration (which was missed somehow).
@capricorn86 capricorn86 linked a pull request May 18, 2023 that will close this issue
@capricorn86
Copy link
Owner

Thank you for reporting @belgattitude! 🙂

I have made a fix that adds support for "prefers-color-scheme" and many more media query features.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v9.19.0

@belgattitude
Copy link
Author

Thanks a lot, this a great feature.

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

Successfully merging a pull request may close this issue.

2 participants