跳转到内容

InputUnstyled API

想要学习更多组件属性和 CSS API,可以查阅 React InputUnstyled 组件的 API 文档。

导入

import InputUnstyled from '@mui/base/InputUnstyled';
// 或
import { InputUnstyled } from '@mui/base';
You can learn about the difference by reading this guide on minimizing bundle size.

属性

原生(Native) 组件的属性也是可用的。

名称类型默认值描述
autoCompletestring
This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill. You can learn more about it following the specification.
autoFocusboolfalse
If true, the input element is focused during the first mount.
classNamestring
Styles applied to the root element.
componentelementType
The component used for the root node. Either a string to use a HTML element or a component.
components{ Input?: elementType, Root?: elementType, Textarea?: elementType }{}
The components used for each slot inside the InputBase. Either a string to use a HTML element or a component.
componentsProps{ input?: func
| object, root?: func
| object }
{}
The props used for each slot inside the Input.
defaultValueany
The default input value. Use when the component is not controlled.
disabledboolfalse
If true, the input element is disabled. The prop defaults to the value (false) inherited from the parent FormControl component.
endAdornmentnode
Trailing adornment for this input.
errorboolfalse
If true, the input will indicate an error. The prop defaults to the value (false) inherited from the parent FormControl component.
idstring
The id of the input element.
maxRowsnumber
Maximum number of rows to display when multiline option is set to true.
minRowsnumber
Minimum number of rows to display when multiline option is set to true.
multilineboolfalse
If true, a textarea element is rendered.
namestring
Name attribute of the input element.
placeholderstring
The short hint displayed in the input before the user enters a value.
readOnlyboolfalse
It prevents the user from changing the value of the field (not from interacting with the field).
requiredboolfalse
If true, the input element is required. The prop defaults to the value (false) inherited from the parent FormControl component.
rowsnumber
Number of rows to display when multiline option is set to true.
startAdornmentnode
Leading adornment for this input.
type'button'
| 'checkbox'
| 'color'
| 'date'
| 'datetime-local'
| 'email'
| 'file'
| 'hidden'
| 'image'
| 'month'
| 'number'
| 'password'
| 'radio'
| 'range'
| 'reset'
| 'search'
| 'submit'
| 'tel'
| 'text'
| 'time'
| 'url'
| 'week'
'text'
Type of the input element. It should be a valid HTML5 input type.
valueany
The value of the input element, required for a controlled component.

ref 则会被传递到根元素中。

演示项目