diff --git a/.changeset/popular-moons-sip.md b/.changeset/popular-moons-sip.md new file mode 100644 index 00000000000..aceddc588c7 --- /dev/null +++ b/.changeset/popular-moons-sip.md @@ -0,0 +1,5 @@ +--- +"@kaizen/components": patch +--- + +fix(useMediaQueries): values will now update when jumping from small to large, or vice versa diff --git a/packages/components/src/utils/useMediaQueries.tsx b/packages/components/src/utils/useMediaQueries.tsx index 2c2bec9e0f0..557b76dae7b 100644 --- a/packages/components/src/utils/useMediaQueries.tsx +++ b/packages/components/src/utils/useMediaQueries.tsx @@ -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) { @@ -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) } }, [])