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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/mui-material/src/OutlinedInput/OutlinedInput.js
Expand Up @@ -155,11 +155,26 @@ const OutlinedInput = React.forwardRef(function OutlinedInput(inProps, ref) {
states: ['required'],
});

const ownerState = {
...props,
color: fcs.color || 'primary',
disabled: fcs.disabled,
error: fcs.error,
focused: fcs.focused,
formControl: muiFormControl,
fullWidth,
hiddenLabel: fcs.hiddenLabel,
multiline,
size: fcs.size,
type,
};

return (
<InputBase
components={{ Root: OutlinedInputRoot, Input: OutlinedInputInput, ...components }}
renderSuffix={(state) => (
<NotchedOutlineRoot
ownerState={ownerState}
className={classes.notchedOutline}
label={
label != null && label !== '' && fcs.required ? (
Expand Down
24 changes: 24 additions & 0 deletions packages/mui-material/src/OutlinedInput/OutlinedInput.test.js
@@ -1,6 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from 'test/utils';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import OutlinedInput, { outlinedInputClasses as classes } from '@mui/material/OutlinedInput';
import InputBase from '@mui/material/InputBase';

Expand Down Expand Up @@ -59,4 +60,27 @@ describe('<OutlinedInput />', () => {
);
expect(document.querySelector('[data-test=test]')).toHaveComputedStyle({ marginTop: '10px' });
});

it('should have ownerState in the theme style overrides', () => {
expect(() =>
render(
<ThemeProvider
theme={createTheme({
components: {
MuiOutlinedInput: {
styleOverrides: {
root: ({ ownerState }) => ({
// test that ownerState is not undefined
...(ownerState.disabled && {}),
}),
},
},
},
})}
>
<OutlinedInput />
</ThemeProvider>,
),
).not.to.throw();
});
});