mui / mui/material-ui

[joy-ui] Make the size prop breakpoint-aware

Open
#41,402 1 comment 8 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since Mar 8, 2024.

on hold package: joy-ui scope: all components type: new feature waiting for 👍
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Summary

Take a look at this code snippet:

<IconButton size="lg">{icon}</IconButton>

If you want to change the size prop on certain screen sizes with Material UI, you can use hooks:

import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';

function MyComponent() {
  const theme = useTheme();
  const matches = useMediaQuery(theme.breakpoints.up('sm'));

  return <IconButton size={matches ? "sm" : "lg"}>{icon}</IconButton>;
}

Often it might be too complicated for a simple task. However, it helps us reuse the predefined settings in Material UI's design system. The size prop not only changes the font size but could also affects other properties like margin, padding, height, and width etc ...

With Joy UI, we have to redefine each property separately, which can lead to inconsistencies:

<IconButton
  sx={{
    "--Icon-fontSize": {xs: "new val", md: "new val"},
    "--IconButton-size": {xs: "new val", md: "new val"},
    and other vars ...
  }}
>

It would be better to stay within the design system and respect the predefined settings that were already set up.

One suggestion is to add support for props to handle breakpoint changes, similar to how ButtonGroup already supports this:

<ButtonGroup spacing={{ xs: 0, sm: 1, md: '2rem' }}>...</ButtonGroup>

This approach would allow you to write something like:

<IconButton size={{xs: "lg", md: "lg"}}>{icon}</IconButton>;

This way, we can easily change the size prop based on different screen sizes while still using the predefined settings in the design system.

Examples

No response

Motivation

No response

Search keywords: breakpoint

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.