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

[Select] Fix className overwritten #25815

Merged
merged 6 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/material-ui/src/Select/Select.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { deepmerge } from '@material-ui/utils';
import SelectInput from './SelectInput';
import formControlState from '../FormControl/formControlState';
Expand Down Expand Up @@ -86,6 +87,7 @@ const Select = React.forwardRef(function Select(inProps, ref) {
...(multiple && native && variant === 'outlined' ? { notched: true } : {}),
ref,
...other,
className: clsx(other.className, InputComponent.props.className),
});
});

Expand All @@ -112,6 +114,10 @@ Select.propTypes /* remove-proptypes */ = {
* @default {}
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The default value. Use when the component is not controlled.
*/
Expand Down
11 changes: 10 additions & 1 deletion packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
fireEvent,
screen,
} from 'test/utils';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
import { createMuiTheme, ThemeProvider, experimentalStyled } from '@material-ui/core/styles';
import MenuItem from '@material-ui/core/MenuItem';
import InputBase from '@material-ui/core/InputBase';
import OutlinedInput from '@material-ui/core/OutlinedInput';
import InputLabel from '@material-ui/core/InputLabel';
import Select from '@material-ui/core/Select';
Expand Down Expand Up @@ -1184,4 +1185,12 @@ describe('<Select />', () => {
nativeInputStyle,
);
});

it('styled Select with custom input should not overwritten className', () => {
const StyledSelect = experimentalStyled(Select)();
const { getByTestId } = render(
<StyledSelect input={<InputBase data-testid="root" className="some-classname" />} value="" />,
);
expect(getByTestId('root')).to.have.class('some-classname');
});
});