Skip to content

Commit

Permalink
also fix NativeSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Apr 18, 2021
1 parent dc3594f commit b1af7ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/material-ui/src/NativeSelect/NativeSelect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import NativeSelectInput from './NativeSelectInput';
import formControlState from '../FormControl/formControlState';
Expand All @@ -14,6 +15,7 @@ const defaultInput = <Input />;
const NativeSelect = React.forwardRef(function NativeSelect(inProps, ref) {
const props = useThemeProps({ name: 'MuiNativeSelect', props: inProps });
const {
className,
children,
classes,
IconComponent = ArrowDropDownIcon,
Expand Down Expand Up @@ -45,6 +47,7 @@ const NativeSelect = React.forwardRef(function NativeSelect(inProps, ref) {
},
ref,
...other,
className: clsx(className, input.props.className),
});
});

Expand All @@ -62,6 +65,10 @@ NativeSelect.propTypes /* remove-proptypes */ = {
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The icon that displays the arrow.
* @default ArrowDropDownIcon
Expand Down
15 changes: 14 additions & 1 deletion packages/material-ui/src/NativeSelect/NativeSelect.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
import { createMuiTheme, ThemeProvider, experimentalStyled } from '@material-ui/core/styles';
import { createMount, createClientRender, describeConformanceV5 } from 'test/utils';
import NativeSelect, { nativeSelectClasses as classes } from '@material-ui/core/NativeSelect';
import Input, { inputClasses } from '@material-ui/core/Input';
Expand Down Expand Up @@ -92,4 +92,17 @@ describe('<NativeSelect />', () => {

expect(container.getElementsByClassName(classes.icon)[0]).to.toHaveComputedStyle(iconStyle);
});

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

0 comments on commit b1af7ab

Please sign in to comment.