css-mediaquery icon indicating copy to clipboard operation
css-mediaquery copied to clipboard

Bug in min-width and max-width matching with em values

Open kimmobrunfeldt opened this issue 6 years ago • 2 comments

We noticed a strange behavior when trying to do matches. Issue demostrated below:

> const css = require('css-mediaquery')
undefined
> css.match('screen and (min-width: 48em)', { width: '48em' })
false
> css.match('screen and (max-width: 48em)', { width: '48em' })
false

I think these both should return true. That's how Chrome matchMedia()works when tested.

kimmobrunfeldt avatar Jan 09 '19 14:01 kimmobrunfeldt

It seems to work when wrapping the whole expression with parentheses like this:

> css.match('(screen and (min-width: 48em))', { width: '48em' })
true

kimmobrunfeldt avatar Jan 09 '19 14:01 kimmobrunfeldt

Your example is not working because this library uses all as the default type:

> css.match('(min-width: 48em)', { width: '48em' })
true
>  css.match('all and (min-width: 48em)', { width: '48em' })
true

You can get your example to return true if you pass screen as the type:

> css.match('screen and (min-width: 48em)', { width: '48em', type: 'screen' })
true

kristerkari avatar Jan 26 '19 23:01 kristerkari