mui / mui/material-ui

No way to define Box variants?

Open
#29,524 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component: Box scope: system support: question
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Should we be able to provide styleOverrides, defaultProps or variants for Box?

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

I'm not sure if this is a bug, or if it's by design. Considering the flexibility of Box I can see where it might be difficult to do.

We've been making extensive use of the ability to declare our own variants for various mui components and have found it to be more desirable than dealing with classNames.

One component that doesn't seem to work with this model, however, is Box.
I've searched the existing issues as best I can but keep coming up empty, and haven't seen anyone else discussing Box variants. I'm hoping I've just missed something.

Here's a simplified example:

const theme = createTheme({
  components: {
    MuiBox: {
      variants: [
        {
          props: { variant: 'error' },
          style: {
            border: '3px dashed red',
            textAlign: 'center'
          },
        }
      ],
    },
  }
})

I've also tried with other props such as data-variant="error", in case it's just that Box doesn't recognize 'variant'.

Expected Behavior 🤔

MuiBox variants, defaultProps and styleOverrides should work as they do with other components.

Steps to Reproduce 🕹

While working on setting up this codebox, I noticed that MuiBox is not present in components.d.ts, so I guess this is more of a feature request than a bug report :-/

https://codesandbox.io/s/heuristic-water-pzsoz

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.

Research direction

Start with the MuiBox configuration described in the issue and inspect components.d.ts, where MuiBox is currently absent. Reproduce the behavior in the linked CodeSandbox using variants, defaultProps, and styleOverrides. Done means Box supports these theme settings consistently with other components and the corresponding type declarations are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.