Skip to content

Allow creating sx container queries from breakpoint keys #45868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GMchris opened this issue Apr 10, 2025 · 1 comment
Open

Allow creating sx container queries from breakpoint keys #45868

GMchris opened this issue Apr 10, 2025 · 1 comment
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system

Comments

@GMchris
Copy link

GMchris commented Apr 10, 2025

Summary

Right now you can create container queries easily by providing a @ prefixed value as the key in sx. You can also use the containerQueries helper alongside theme breakpoints on the theme object to create an at rule by writing theme.containerQueries.up('sm').

Examples

It'd be convenient to use the built-in theme breakpoint values here. Something like this:

<Box
    sx={{
        padding: {
          '@sm': 1,
          '@md': 2,
          '@': 3,
        }
    }}
/>

Which would be interpreted as

<Box
    sx={{
        padding: {
          '@600': 1,
          '@900': 2,
          '@': 3,
        }
    }}
/>

Motivation

This would streamline creating container query powered styles, as I typically want to use values set by our design system. Right now my approach is verbose in the form of

const theme = useTheme();


<Box
    sx={{
        padding: {
          [`@${theme.breakpoints.values.sm}`]: 1,
          [`@${theme.breakpoints.values.md}`]: 2,
          '@': 3,
        }
    }}
/>

Search keywords: container query, sx, breakpoint

@GMchris GMchris added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 10, 2025
@siriwatknp siriwatknp added enhancement This is not a bug, nor a new feature package: system Specific to @mui/system and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 10, 2025
@siriwatknp
Copy link
Member

Having it would be a nice thing but I want to see the code changes first. If the added logic does not create more runtime calculation, I am happy to merge the PR.

Do you want to propose an implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system
Projects
None yet
Development

No branches or pull requests

2 participants