본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Input API

원문 보기 위키 갱신

Input API (입력 API)

Input은 텍스트 입력 필드를 제공하는 컴포넌트예요. 이 페이지에서는 이 컴포넌트의 props, CSS 클래스, 그리고 기타 API를 하나씩 설명해 드릴게요.

출처: 문서

본문

데모 (Demos)

이 React 컴포넌트의 사용법과 세부 사항은 컴포넌트 데모 페이지에서 확인할 수 있어요.

  • Text Field

Import

import Input from '@mui/material/Input';
// 또는
import { Input } from '@mui/material';

번들 크기를 줄이는 방법이 궁금하시다면, 이 차이에 대한 가이드 문서를 읽어 보시면 좋아요.

Props

InputBase 컴포넌트의 props도 그대로 사용할 수 있어요.

Name Type Default Description
autoComplete string - 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.
autoFocus bool - If true, the input element is focused during the first mount.
classes object - Override or extend the styles applied to the component. See CSS classes API below for more details.
color 'primary'| 'secondary'| string - The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide. The prop defaults to the value ('primary') inherited from the parent FormControl component.
defaultValue any - The default value. Use when the component is not controlled.
disabled bool - If true, the component is disabled. The prop defaults to the value (false) inherited from the parent FormControl component.
disableUnderline bool false If true, the input will not have an underline.
endAdornment node - End InputAdornment for this component.
error bool - If true, the input will indicate an error. The prop defaults to the value (false) inherited from the parent FormControl component.
fullWidth bool false If true, the input will take up the full width of its container.
id string - The id of the input element.
inputComponent elementType 'input' The component used for the input element. Either a string to use a HTML element or a component.
inputProps object {} Attributes applied to the input element.
inputRef ref - Pass a ref to the input element.
margin 'dense'| 'none' - If dense, will adjust vertical spacing. This is normally obtained via context from FormControl. The prop defaults to the value ('none') inherited from the parent FormControl component.
maxRows number| string - Maximum number of rows to display when multiline option is set to true.
minRows number| string - Minimum number of rows to display when multiline option is set to true.
multiline bool false If true, a TextareaAutosize element is rendered.
name string - Name attribute of the input element.
onChange func - Callback fired when the value is changed. Signature: function(event: React.ChangeEvent) => void. event The event source of the callback. You can pull out the new value by accessing event.target.value (string).
placeholder string - The short hint displayed in the input before the user enters a value.
readOnly bool - It prevents the user from changing the value of the field (not from interacting with the field).
required bool - If true, the input element is required. The prop defaults to the value (false) inherited from the parent FormControl component.
rows number| string - Number of rows to display when multiline option is set to true.
slotProps { input?: object, root?: object } {} The extra props for the slot components. You can override the existing props or add new ones.
slots { input?: elementType, root?: elementType } {} The components used for each slot inside.
startAdornment node - Start InputAdornment for this component.
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.
type string 'text' Type of the input element. It should be a valid HTML5 input type.
value any - The value of the input element, required for a controlled component.

ref는 루트 요소로 전달돼요.

상속 (Inheritance)

위에서 명시적으로 다루지는 않았지만, InputBase 컴포넌트의 props도 Input에서 사용할 수 있어요. 이를 활용해 중첩된 컴포넌트를 대상으로 지정할 수 있어요.

테마 기본 props (Theme default props)

MuiInput을 사용하면 테마를 통해 이 컴포넌트의 기본 props를 바꿀 수 있어요.

CSS 클래스 (CSS classes)

이 클래스들은 CSS로 스타일을 지정할 때 유용해요. 특정 상태가 트리거되면 컴포넌트의 슬롯에 적용돼요.

Class name Rule name Description
.Mui-disabled Styles applied to the root element if disabled={true}.
.Mui-error State class applied to the root element if error={true}.
.Mui-focused Styles applied to the root element if the component is focused.
.MuiInput-colorSecondary colorSecondary Styles applied to the root element if color secondary.
.MuiInput-formControl formControl Styles applied to the root element if the component is a descendant of FormControl.
.MuiInput-fullWidth fullWidth Styles applied to the root element if fullWidth={true}.
.MuiInput-input input Styles applied to the input element.
.MuiInput-inputTypeSearch inputTypeSearch Styles applied to the input element if type="search".
.MuiInput-multiline multiline Styles applied to the root element if multiline={true}.
.MuiInput-root root Styles applied to the root element.
.MuiInput-sizeSmall sizeSmall Styles applied to the input element if size="small".
.MuiInput-underline underline Styles applied to the root element unless disableUnderline={true}.

컴포넌트의 스타일을 다음 방법 중 하나로 재정의할 수 있어요.

  • 전역 클래스 이름으로 재정의하기
  • 커스텀 테마의 컴포넌트 styleOverrides 속성에 규칙 이름(rule name)으로 재정의하기

소스 코드 (Source code)

이 페이지에서 원하는 정보를 찾지 못했다면, 컴포넌트의 구현 코드를 살펴보시면 더 자세한 내용을 확인할 수 있어요.

더 알아보기