[system] Apply theme variants to all slots by default#48503
[system] Apply theme variants to all slots by default#48503starboyvarun wants to merge 1 commit into
Conversation
Deploy previewhttps://deploy-preview-48503--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
|
|
||
| ## Merged / In-Review Contributions | ||
|
|
||
| | PR | Branch | Description | Author focus | | ||
| | :- | :----- | :---------- | :----------- | | ||
| | [#48500](https://github.com/mui/material-ui/pull/48500) | `36479-focus-trap-tabindex-order` | Fix FocusTrap `sentinelStart` `tabIndex` so it wins over positive-`tabIndex` children | oliviertassinari | | ||
| | [#48501](https://github.com/mui/material-ui/pull/48501) | `35939-typography-custom-variant-fontfamily` | Inject `fontFamily`/`allVariants` into custom typography variants in `createTypography` | siriwatknp | | ||
| | [#48502](https://github.com/mui/material-ui/pull/48502) | `39296-tabs-scroll-button-rtl-slots` | Fix `TabScrollButton` picking wrong slot icon in RTL mode | mj12albert | | ||
| | [#48503](https://github.com/mui/material-ui/pull/48503) | `44272-styled-slot-variants` | Remove `skipVariantsResolver=true` default for non-root slots so theme variants apply everywhere | siriwatknp | | ||
|
|
||
| ### Key internals learned | ||
|
|
||
| - **`createStyled.js` `skipVariantsResolver`** — was `true` for any non-root slot; changing to `false` makes `theme.components[X].variants` consistent with `styleOverrides` (which already applies to all slots). | ||
| - **`FocusTrap` sentinel ordering** — `sentinelStart` must have `tabIndex={1}` (not `0`) so it beats any positive-`tabIndex` child in forward tab order and keeps focus trapped. | ||
| - **`createTypography` `other` spread** — custom variants passed via the `other` bag bypass `buildVariant`; must pre-process them to inject `fontFamily`/`allVariants` before `deepmerge`. | ||
| - **`TabScrollButton` RTL icon slots** — correct XOR: `(direction === 'left') !== isRtl` maps semantic Start/End slots to visual direction in both LTR and RTL. |
There was a problem hiding this comment.
We are open to AI tools but please sanity check your output (manually) before opening PRs 🙏
There was a problem hiding this comment.
Sorry about that — I accidentally staged a local scratch file I keep for notes while exploring the codebase. It shouldn't have been part of this PR at all. Removed it from the branch now.
| : // TODO v6: remove `Root` in the next major release | ||
| // For more details: https://github.com/mui/material-ui/pull/37908 | ||
| (componentSlot && componentSlot !== 'Root' && componentSlot !== 'root') || false; | ||
| const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver : false; |
There was a problem hiding this comment.
Does this fix the repro in the linked issue?
There was a problem hiding this comment.
Yes — the fix directly addresses the repro. The issue is that skipVariantsResolver defaulted to rue for any slot whose name was not 'Root'/'root', so heme.components[X].variants was silently skipped for slots like icon, label, etc. The styleOverrides block has no such restriction and already applies to all slots.
The one-line change removes that slot-name condition so variants follow the same rules as overrides. processStyleVariants already checks both props[key] and props.ownerState?.[key] when matching, so variant conditions that depend on ownerState props work correctly for non-root slots without any further changes.
There was a problem hiding this comment.
I had a look at the repro, can you explain a bit how you arrived at your conclusions?
2a001c7 to
7cb8025
Compare
Previously `skipVariantsResolver` defaulted to `true` for any non-root slot, which silently prevented `theme.components[X].variants` from applying to slots like `icon`, `label`, etc. This was inconsistent with `styleOverrides`, which already works for all slots. Remove the slot-name-based default so `skipVariantsResolver` is `false` for all slots unless explicitly opted out. Fixes mui#44272
7cb8025 to
04b2cf7
Compare
|
@mj12albert const skipVariantsResolver =
inputSkipVariantsResolver !== undefined
? inputSkipVariantsResolver
: (componentSlot && componentSlot !== 'Root' && componentSlot !== 'root') || false;Any slot other than The fix removes the slot-based default and always defaults to |
It looks to me the repro doesn't use this API and involves a different code path |
Fixes #44272
Problem
theme.components[X].variantssilently had no effect for any slot other thanRoot/root. The root cause:skipVariantsResolverdefaulted totruefor any non-root slot name (e.g.icon,label,track), which caused the variants resolution block to be skipped entirely.This was inconsistent with
styleOverrides, which already applies to every slot.Fix
Remove the slot-name condition so
skipVariantsResolverisfalsefor all slots unless explicitly opted out withskipVariantsResolver: true.Tests