css-mediaquery
css-mediaquery copied to clipboard
Bug in min-width and max-width matching with em values
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.
It seems to work when wrapping the whole expression with parentheses like this:
> css.match('(screen and (min-width: 48em))', { width: '48em' })
true
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