Select API
导入
import Select from '@mui/material/Select';
// 或
import { Select } from '@mui/material';组件名称
在主题中,名称“MuiSelect”可用于提供默认属性(props),或者样式覆盖属性
OutlinedInput 组件的属性也是可用的。
| 名称 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| autoWidth | bool | false | If  true, the width of the popover will automatically be set according to the items inside the menu, otherwise it will be at least the width of the select input. | 
| children | node | The option elements to populate the select with. Can be some  MenuItemwhennativeis false andoptionwhennativeis true.⚠️The MenuItemelements must be direct descendants whennativeis false. | |
| classes | object | {} | Override or extend the styles applied to the component. See CSS API below for more details. | 
| defaultOpen | bool | false | If  true, the component is initially open. Use when the component open state is not controlled (i.e. theopenprop is not defined). You can only use it when thenativeprop isfalse(default). | 
| defaultValue | any | The default input value. Use when the component is not controlled. | |
| displayEmpty | bool | false | If  true, a value is displayed even if no items are selected.In order to display a meaningful value, a function can be passed to the renderValueprop which returns the value to be displayed when no items are selected.⚠️ When using this prop, make sure the label doesn't overlap with the empty displayed value. The label should either be hidden or forced to a shrunk state. | 
| IconComponent | elementType | ArrowDropDownIcon | The icon that displays the arrow. | 
| id | string | The  idof the wrapper element or theselectelement whennative. | |
| input | element | An  Inputelement; does not have to be a material-ui specificInput. | |
| inputProps | object | Attributes applied to the  inputelement. Whennativeistrue, the attributes are applied on theselectelement. | |
| label | node | ||
| labelId | string | The ID of an element that acts as an additional label. The Select will be labelled by the additional label and the selected value. | |
| MenuProps | object | Props applied to the  Menuelement. | |
| multiple | bool | false | If  true,valuemust be an array and the menu will support multiple selections. | 
| native | bool | false | If  true, the component uses a nativeselectelement. | 
| onChange | func | Callback fired when a menu item is selected. Signature: function(event: object, child?: object) => voidevent: The event source of the callback. You can pull out the new value by accessing event.target.value(any). Warning: This is a generic event not a change event.child: The react element that was selected when nativeisfalse(default). | |
| onClose | func | Callback fired when the component requests to be closed. Use in controlled mode (see open). Signature: function(event: object) => voidevent: The event source of the callback. | |
| onOpen | func | Callback fired when the component requests to be opened. Use in controlled mode (see open). Signature: function(event: object) => voidevent: The event source of the callback. | |
| open | bool | false | Control  selectopen state. You can only use it when thenativeprop isfalse(default). | 
| renderValue | func | Render the selected value. You can only use it when the  nativeprop isfalse(default).Signature: function(value: any) => ReactNodevalue: The valueprovided to the component. | |
| SelectDisplayProps | object | Props applied to the clickable div element. | |
| sx | Array<func | object | bool> | func | object | The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details. | |
| value | '' | any | The  inputvalue. Providing an empty string will select no options. This prop is required when thenativeprop isfalse(default). Set to an empty string''if you don't want any of the available options to be selected.If the value is an object it must have reference equality with the option in order to be selected. If the value is not an object, the string representation must match with the string representation of the option in order to be selected. | |
| variant | 'filled' | 'outlined' | 'standard' | 'outlined' | The variant to use. | 
ref 则会被传递到根元素中。继承
尽管上文没有明文记录, OutlinedInput 组件 的属性(props) 在组件Select上同样是可用的。 你可以利用这一点来 指向嵌套组件CSS
| 规则名称 | 全局类名 | 描述 | 
|---|---|---|
| select | .MuiSelect-select | Styles applied to the select component `select` class. | 
| multiple | .MuiSelect-multiple | Styles applied to the select component if multiple={true}. | 
| filled | .MuiSelect-filled | Styles applied to the select component if variant="filled". | 
| outlined | .MuiSelect-outlined | Styles applied to the select component if variant="outlined". | 
| standard | .MuiSelect-standard | Styles applied to the select component if variant="standard". | 
| disabled | .Mui-disabled | Pseudo-class applied to the select component `disabled` class. | 
| icon | .MuiSelect-icon | Styles applied to the icon component. | 
| iconOpen | .MuiSelect-iconOpen | Styles applied to the icon component if the popup is open. | 
| iconFilled | .MuiSelect-iconFilled | Styles applied to the icon component if variant="filled". | 
| iconOutlined | .MuiSelect-iconOutlined | Styles applied to the icon component if variant="outlined". | 
| iconStandard | .MuiSelect-iconStandard | Styles applied to the icon component if variant="standard". | 
| nativeInput | .MuiSelect-nativeInput | Styles applied to the underlying native input component. | 
您可以使用组件自定义选项对组件进行个性化:
- 具备 全局类名.
- 在自定义主体中,设定一个规则名称作为组件的styleOverrides属性的一部分。