[Joy] Media query usage
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Summary š”
Iād like to be able to import and use useMediaQuery with Joy UI just like Material UI supports to adapt my layout for different screen sizes
Examples š
import { Button, IconButton, useMediaQuery } from '@mui/joy'
import SettingsIcon from '@mui/icons-material/Settings'
const NavigationBar = () => {
let isScreenMobile = useMediaQuery((theme) =>
theme.breakpoints.down('mobile')
)
return (
<div>
{isScreenMobile ? (
<Button startDecorator={<SettingsIcon />}>
Settings
</Button>
) : (
<IconButton>
<SettingsIcon />
</IconButton>
)}
</div>
)
}
Motivation š¦
Iām trying to adapt my interface to have my navigation bar show just an IconButton when on a tablet or larger sized screen, but a larger regular Button with an icon when on a mobile sized screen. At the moment I appear to be unable to do so without something like useMediaQuery which has access to my themeās media breakpoints, which makes the app less friendly and functional on mobile. While the sx prop is very useful for adapting individual components, itās common to want to render entirely different components at different breakpoints.
For reference, my breakpoints are set to:
mobile: 0,
tablet: 640,
laptop: 1024,
desktop: 1200
Many well-designed web apps like Twitter have elements like side bars that collapse, disappear completely (like the āWhatās happeningā bar on the righthand side) or are replaced by new layouts (like the navigation bar on the lefthand side, which collapses at smaller sizes and is wholly replaced by a bottom navigation bar on mobile). This kind of adaptability is essential for designing a responsive/mobile-friendly app.
If thereās a workaround in the meantime Iād be happy to learn it! I love the aesthetic of Joy UI much more than Material UI 2, so am eager and making an effort to use it although itās still in alpha.
Issue Analytics
- State:
- Created 10 months ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
After reading the original issue, it is not about the Modal. I will try to add some docs about the media query to Joy UI.
Honestly, I donāt recommend using JS to switch between layouts. Always use CSS if you can.
This is better for sure:
I am changing this issue to a question instead.