Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OutlinedInput] Fix ownerState undefined in theme style overrides #33241

Merged
merged 3 commits into from Jun 23, 2022

Conversation

siriwatknp
Copy link
Member

closes #31982

Root cause

No ownerState is provided to NotchedOutlineRoot. This is strange at first because the NotchedOutlinedRoot slot is not root but why the ownerState is logged.

const theme = createTheme({
  components: {
    MuiOutlinedInput: {
      styleOverrides: {
        root: ({ ownerState }) => {
          console.log('MuiOutlinedInput ownerState', ownerState);
          return {};
        },
      },
    },
  },
});

Each slot traverses the styleOverrides and passes props if the value is a function. In the end, the slot picks the resolved styles. That's why the callback is called multiple times even though it is declared on the root slot style overrides.

We can't use @oliviertassinari 's fix at this point because it will be breaking changes. This is one example from InputBase:

export const InputBaseRoot = styled('div', {
  name: 'MuiInputBase',
  slot: 'Root',
  overridesResolver: (props, styles) => {
    const { ownerState } = props;
    return [
      styles.root,
      ownerState.formControl && styles.formControl,
      ownerState.startAdornment && styles.adornedStart,
      ownerState.endAdornment && styles.adornedEnd,
      ownerState.error && styles.error,
      ownerState.size === 'small' && styles.sizeSmall,
      ownerState.multiline && styles.multiline,
      ownerState.color && styles[`color${capitalize(ownerState.color)}`],
      ownerState.fullWidth && styles.fullWidth,
      ownerState.hiddenLabel && styles.hiddenLabel,
    ];
  },
})

Here is the InputBase root slot which looks for other various keys.

We could do the fix in v6 as breaking changes.

@siriwatknp siriwatknp added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels Jun 21, 2022
@mui-bot
Copy link

mui-bot commented Jun 21, 2022

Details of bundle changes

Generated by 🚫 dangerJS against 6c8bdee

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, left similar comment in #31982 (comment)

We would need to have a list of style overrides the component needs in order for this to work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TextField] MuiOutlinedInput callback in styleOverrides sometimes passes ownerState as undefined
3 participants