Input
Input (입력 상자)
사용자가 텍스트 상자에 내용을 입력할 수 있게 해 주는 컴포넌트예요. 지우기 버튼, 글자 수 표시, 포맷터 같은 실무에서 자주 필요한 기능을 옵션으로 제공해요.
출처: 문서
본문
소개 (Intro)
사용자가 텍스트 상자에 내용을 입력할 수 있어요.
설치 (Install)
import { createApp } from 'vue'
import { Input } from '@nutui/nutui'
const app = createApp()
app.use(Input)
데모 (Demos)
아래 항목들은 원문 문서의 대화형 데모로 제공돼요.
- 기본 사용법 (Basic Usage) —
demo: input basic - 커스텀 타입 (Custom Type) —
demo: input type - 읽기 전용과 비활성화 (Readonly And Disabled) —
demo: input status - 지우기 아이콘 표시 (Show Clear Icon) —
demo: input clear - 폼과 함께 사용 (Use With Form) —
demo: input form - 값 포맷 (Format Value) —
demo: input format - 글자 수 제한 표시 (Show Word Limit) —
demo: input count - 테두리 없음 (No Border) —
demo: input border - 입력 정렬 (Input Align) —
demo: input align - 이벤트 (Event) —
demo: input event - 슬롯 (Slot) —
demo: input slot
기본 사용법 (Basic Usage)
필드 값은 v-model로 바인딩해요.
지우기 아이콘 표시 (Show Clear Icon)
clearable을 설정하면 입력 중에 지우기 아이콘이 표시돼요. 포커스를 잃으면 지우기 버튼은 숨겨져요. showClearIcon으로 포커스를 잃은 뒤에도 지우기 버튼을 계속 표시하도록 설정할 수 있어요.
폼과 함께 사용 (Use With Form)
nut-form과 nut-form-item과 조합해서 사용해요.
값 포맷 (Format Value)
formatter prop을 사용해 입력 값을 포맷해요.
글자 수 제한 표시 (Show Word Limit)
maxlength와 show-word-limit 속성을 설정하면 하단에 글자 수가 표시돼요.
API
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| v-model | Input value, two-way binding | string | number | - |
| type | Input type, support all native types and number digit type |
string | text |
| placeholder | Placeholder when the input box is empty | string | - |
| input-align | Input align, eg left、center、right |
string | left |
| required | Whether to show required mark | boolean | false |
| border | Whether to show inner borde | boolean | true |
| disabled | Whether to disable field | boolean | false |
| readonly | Whether to be readonly | boolean | false |
| autofocus | Whether to auto focus, unsupported in iOS | boolean | false |
| max-length | Max length of value | string | number | - |
| clearable | Whether to be clearable | boolean | false |
show-clear-icon 4.0.2 |
Whether to continue to display the clear button after losing focus, which will take effect when 'clearable' is set | boolean | false |
| clear-size | Clear Icon font-size |
string | 14 |
| show-word-limit | Whether to show word limit, need to set the max-length prop |
boolean | false |
| error | Whether to mark the input content in red | boolean | false |
| formatter | Input value formatter | (val: string) => string |
- |
| format-trigger | When to format value, eg onChange、onBlur |
string | onChange |
| confirm-type | The text of the button in the lower right corner of the keyboard, only valid when type='text', eg send, search, next, go, done |
string | done |
Events
| Event | Description | Arguments |
|---|---|---|
| update:model-value | Emitted when input value changed | val |
| focus | Emitted when input is focused | event |
| blur | Emitted when input is blurred | event |
| clear | Emitted when the clear icon is clicked | event |
| click | Emitted when component is clicked | event |
| click-input | Emitted when the input is clicked | event |
confirm4.2.1 |
Triggered when you click the soft keyboard to confirm | event |
Slots
| Name | Description |
|---|---|
| clear | Customize the end of the input box to clear the button |
left 4.0.1 |
Customize the slot content on the left side of the input box |
right 4.0.1 |
Customize the slot content on the right side of the input box |
Ref
| Name | Description |
|---|---|
focus 4.0.6 |
Focus |
blur 4.0.6 |
Blur |
select 4.0.6 |
Selct |
Types v4.3.7
컴포넌트는 다음 타입 정의를 export해요:
import type {
InputType,
InputAlign,
InputConfirmType,
InputFormatTrigger,
InputProps,
InputInstance
} from '@nutui/nutui'
Theming
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value |
|---|---|
| --nut-input-border-bottom | #eaf0fb |
| --nut-input-disabled-color | #c8c9cc |
| --nut-input-required-color | var(--nut-required-color) |
| --nut-input-font-size | var(--nut-font-size-2) |
더 알아보기 (Learn more)
- 원문 문서: Input — NutUI v4 영문 문서
- NutUI 저장소: jd-opensource/nutui