panda icon indicating copy to clipboard operation
panda copied to clipboard

Container query sizes converted to em units

Open ejhammond opened this issue 2 years ago • 3 comments

Description

When I specify a container size in px units, the generated utility class css converts my value to em units. The effect is that my container queries don't behave as expected when the font size is changed.

In my app I have some content that should be hidden when its container is < 600px. Panda generates a container query based on 1em = 16px and so the result is 37.5em. But this area of my app has a font size of 1.25em (20px) so the container query triggers at 20*37.5 = 750px rather than 600px.

I think that the generated container queries should probably not convert to em units.

Link to Reproduction

link

Steps to reproduce

Check the config and note:

containerSizes: { 100: '100px' }

Check the generated CSS (in the utilities layer) and note:

  @container (min-width: 6.25em) {
    .\@\/100\:d_none {
      display: none;
    }

JS Framework

No response

Panda CSS Version

0.31.0

Browser

No response

Operating System

  • [ ] macOS
  • [ ] Windows
  • [ ] Linux

Additional Information

No response

ejhammond avatar Feb 14 '24 18:02 ejhammond

This em conversion appears intentional, though I couldn't find much context as to why.

Line: https://github.com/chakra-ui/panda/blame/fe3a686bcd08f8d7a333b86a4555d30c7431878a/packages/core/src/conditions.ts#L51

Commit: https://github.com/chakra-ui/panda/pull/2099/commits/cff13424234807eeec268979ba8e7cd9569fa6c7

cc @segunadebayo do you remember why you added this?

ejhammond avatar Feb 14 '24 20:02 ejhammond

@ejhammond. The thinking was to keep it consistent with how we handle media queries, but that might only sometimes be needed.

Container sizes can be contextual, and using ems might have some side effects, as you've described. Let me think about this some more.

segunadebayo avatar Feb 14 '24 22:02 segunadebayo

Related, I'm not sure it's the best idea for media queries as well. I'm heavily consulting on this guide for creating a new component library. I think rems could be better than ems for media queries?

adbutterfield avatar Feb 16 '24 01:02 adbutterfield