mui / mui/material-ui

[system] Propagate custom `style` props to component SxProps.

Open
#27,673 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: system type: new feature
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

  • Custom props created using style aren't propagated to the SxProps which enhances each MUI component. While the SxProps prop technically works with any valid CSS, the theme-aware transformers aren't applied.

Examples 🌈

import {Box} from "@material-ui/core"
import styled from "@emotion/styled"
import {style} from "@material-ui/system"

const bgStyle = style({
  cssProperty: "backgroundColor"
  prop: "bg",
  themeKey: "palette",
})

const CustomBox = styled(Box)`
  ${bgStyle};
`

// doesn't work
<CustomBox sx={{bg: "background.primary"}} />

One way to get it working today would be to create a custom Sx function and then override the default Sx prop on each component.

What if we provided additional transformers at the ThemeProvider level? Perhaps we could expose a method to override getThemeValue globally?

Updated example*

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 by reading packages/material-ui-system/src/getThemeValue.js and tracing how SxProps handles custom style props on components. The issue does not name tests or settle whether to add ThemeProvider-level transformers or change getThemeValue globally, so the intended behavior and completion criteria need clarification first.

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
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.