Skip to content

Commit

Permalink
[OutlinedInput] Fix ownerState undefined in theme style overrides (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Jun 23, 2022
1 parent fd279d6 commit ed7972b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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();
});
});

0 comments on commit ed7972b

Please sign in to comment.