Skip to content

Commit

Permalink
fix(useMediaQueries): Add event listeners to small and large instead …
Browse files Browse the repository at this point in the history
…of medium (#5074)
  • Loading branch information
dougmacknz authored Sep 24, 2024
1 parent f58c5b6 commit 3ee2e8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-moons-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kaizen/components": patch
---

fix(useMediaQueries): values will now update when jumping from small to large, or vice versa
8 changes: 5 additions & 3 deletions packages/components/src/utils/useMediaQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const useMediaQueries = (
})

// ---------------------------------------
// Create an event listener based on the medium breakpoint and update state whenever it changes
// Create an event listener based on the small and large breakpoints and update state whenever one of those changes
// ---------------------------------------
useEffect(() => {
if (isLegacyEdge || isUnsupportedSafari) {
Expand All @@ -118,10 +118,12 @@ export const useMediaQueries = (
})
}

mediumMatchMedia.addEventListener("change", updateMatches, true)
smallMatchMedia.addEventListener("change", updateMatches, true)
largeMatchMedia.addEventListener("change", updateMatches, true)

return () => {
mediumMatchMedia.removeEventListener("change", updateMatches)
smallMatchMedia.removeEventListener("change", updateMatches)
largeMatchMedia.removeEventListener("change", updateMatches)
}
}, [])

Expand Down

0 comments on commit 3ee2e8a

Please sign in to comment.