diff --git a/docs/pages/api-docs/native-select.json b/docs/pages/api-docs/native-select.json index 1e6df9459fada5..328c6493e2cda1 100644 --- a/docs/pages/api-docs/native-select.json +++ b/docs/pages/api-docs/native-select.json @@ -6,6 +6,7 @@ "input": { "type": { "name": "element" }, "default": "" }, "inputProps": { "type": { "name": "object" } }, "onChange": { "type": { "name": "func" } }, + "sx": { "type": { "name": "object" } }, "value": { "type": { "name": "any" } }, "variant": { "type": { @@ -37,6 +38,6 @@ "filename": "/packages/material-ui/src/NativeSelect/NativeSelect.js", "inheritance": { "component": "Input", "pathname": "/api/input/" }, "demos": "", - "styledComponent": false, + "styledComponent": true, "cssComponent": false } diff --git a/docs/translations/api-docs/native-select/native-select.json b/docs/translations/api-docs/native-select/native-select.json index b303222f1c7269..eb51c78befe586 100644 --- a/docs/translations/api-docs/native-select/native-select.json +++ b/docs/translations/api-docs/native-select/native-select.json @@ -7,6 +7,7 @@ "input": "An Input element; does not have to be a material-ui specific Input.", "inputProps": "<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes">Attributes</a> applied to the select element.", "onChange": "Callback fired when a menu item is selected.

Signature:
function(event: object) => void
event: The event source of the callback. You can pull out the new value by accessing event.target.value (string).", + "sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.", "value": "The input value. The DOM API casts this to a string.", "variant": "The variant to use." }, diff --git a/packages/material-ui/src/NativeSelect/NativeSelect.d.ts b/packages/material-ui/src/NativeSelect/NativeSelect.d.ts index fc2102f5edaadc..494b7132d4527e 100644 --- a/packages/material-ui/src/NativeSelect/NativeSelect.d.ts +++ b/packages/material-ui/src/NativeSelect/NativeSelect.d.ts @@ -1,5 +1,6 @@ import * as React from 'react'; -import { InternalStandardProps as StandardProps } from '..'; +import { SxProps } from '@material-ui/system'; +import { InternalStandardProps as StandardProps, Theme } from '..'; import { InputProps } from '../Input'; import { NativeSelectInputProps } from './NativeSelectInput'; @@ -58,6 +59,10 @@ export interface NativeSelectProps * You can pull out the new value by accessing `event.target.value` (string). */ onChange?: NativeSelectInputProps['onChange']; + /** + * The system prop that allows defining system overrides as well as additional CSS styles. + */ + sx?: SxProps; /** * The `input` value. The DOM API casts this to a string. */ diff --git a/packages/material-ui/src/NativeSelect/NativeSelect.js b/packages/material-ui/src/NativeSelect/NativeSelect.js index f1c1beea345778..3e234c3a363954 100644 --- a/packages/material-ui/src/NativeSelect/NativeSelect.js +++ b/packages/material-ui/src/NativeSelect/NativeSelect.js @@ -1,11 +1,11 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import NativeSelectInput from './NativeSelectInput'; -import withStyles from '../styles/withStyles'; import formControlState from '../FormControl/formControlState'; import useFormControl from '../FormControl/useFormControl'; import ArrowDropDownIcon from '../internal/svg-icons/ArrowDropDown'; import Input from '../Input'; +import useThemeProps from '../styles/useThemeProps'; export const styles = (theme) => ({ /* Styles applied to the select component `root` class. */ @@ -62,7 +62,7 @@ export const styles = (theme) => ({ }, /* Styles applied to the select component `selectMenu` class. */ selectMenu: { - height: 'auto', // Resets for multiple select with chips + height: 'auto', // Resets for multipile select with chips minHeight: '1.4375em', // Required for select\text-field height consistency textOverflow: 'ellipsis', whiteSpace: 'nowrap', @@ -111,7 +111,8 @@ const defaultInput = ; /** * An alternative to ` {props.multiple ? null : ( - + )} ); @@ -55,7 +155,7 @@ NativeSelectInput.propTypes = { * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ - classes: PropTypes.object.isRequired, + classes: PropTypes.object, /** * The CSS class name of the select element. */ diff --git a/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js b/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js index 4d2044aa7e5249..563a5ce7f9e105 100644 --- a/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js +++ b/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js @@ -1,7 +1,7 @@ import * as React from 'react'; import { expect } from 'chai'; import { spy } from 'sinon'; -import { createMount, describeConformance, createClientRender } from 'test/utils'; +import { createMount, describeConformanceV5, createClientRender } from 'test/utils'; import NativeSelectInput from './NativeSelectInput'; describe('', () => { @@ -25,10 +25,11 @@ describe('', () => { ], }; - describeConformance( {}} />, () => ({ + describeConformanceV5( {}} />, () => ({ mount, only: ['refForwarding'], refInstanceof: window.HTMLSelectElement, + muiName: 'MuiNativeSelectInput', })); it('should render a native select', () => { diff --git a/packages/material-ui/src/NativeSelect/index.d.ts b/packages/material-ui/src/NativeSelect/index.d.ts index b98e687a6d6fa1..026e02bdf5c8a9 100644 --- a/packages/material-ui/src/NativeSelect/index.d.ts +++ b/packages/material-ui/src/NativeSelect/index.d.ts @@ -1,2 +1,4 @@ export { default } from './NativeSelect'; export * from './NativeSelect'; +export { default as nativeSelectClasses } from './nativeSelectClasses'; +export * from './nativeSelectClasses'; diff --git a/packages/material-ui/src/NativeSelect/index.js b/packages/material-ui/src/NativeSelect/index.js index e2f92130f3481e..1377cb53267a13 100644 --- a/packages/material-ui/src/NativeSelect/index.js +++ b/packages/material-ui/src/NativeSelect/index.js @@ -1 +1,3 @@ export { default } from './NativeSelect'; +export { default as nativeSelectClasses } from './nativeSelectClasses'; +export * from './nativeSelectClasses'; diff --git a/packages/material-ui/src/NativeSelect/nativeSelectClasses.d.ts b/packages/material-ui/src/NativeSelect/nativeSelectClasses.d.ts new file mode 100644 index 00000000000000..8f484a275c2fd0 --- /dev/null +++ b/packages/material-ui/src/NativeSelect/nativeSelectClasses.d.ts @@ -0,0 +1,7 @@ +import { NativeSelectClassKey } from './NativeSelect'; + +declare const nativeSelectClasses: Record; + +export function getNativeSelectUtilityClasses(slot: string): string; + +export default nativeSelectClasses; diff --git a/packages/material-ui/src/NativeSelect/nativeSelectClasses.js b/packages/material-ui/src/NativeSelect/nativeSelectClasses.js new file mode 100644 index 00000000000000..70cfb0a4434ee9 --- /dev/null +++ b/packages/material-ui/src/NativeSelect/nativeSelectClasses.js @@ -0,0 +1,21 @@ +import { generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled'; + +export function getNativeSelectUtilitiyClasses(slot) { + return generateUtilityClass('MuiNativeSelect', slot); +} + +const nativeSelectClasses = generateUtilityClasses('MuiNativeSelect', [ + 'root', + 'select', + 'filled', + 'outlined', + 'selectMenu', + 'disabled', + 'icon', + 'iconOpen', + 'iconFilled', + 'iconOutlined', + 'nativeInput', +]); + +export default nativeSelectClasses;