Skip to content

Commit

Permalink
fix(match-media): handle full media queries in breakpoints in useResp…
Browse files Browse the repository at this point in the history
…onsiveValue and useBreakpointIndex hooks
  • Loading branch information
hasparus committed Apr 8, 2022
1 parent 4cc457a commit e574fcf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/match-media/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ export const useBreakpointIndex = (options: defaultOptions = {}) => {
const [value, setValue] = useState(defaultIndex)
useEffect(() => {
const getIndex = () =>
breakpoints.filter(
(bp) => window.matchMedia(`screen and (min-width: ${bp})`).matches
).length
breakpoints.filter((bp) => {
const query = bp.includes('@media')
? bp.slice(7) // remove '@media '
: `screen and (min-width: ${bp})`

return window.matchMedia(query).matches
}).length

const onResize = () => {
const newValue = getIndex()
Expand Down

0 comments on commit e574fcf

Please sign in to comment.