2016-11-10 21:46:55 +08:00
## Input
Input data using mouse or keyboard.
2019-02-25 10:28:14 +08:00
:::warning
Input is a controlled component, it **always shows Vue binding value** .
Under normal circumstances, `input` event should be handled. Its handler should update component's binding value (or use `v-model` ). Otherwise, input box's value will not change.
Do not support `v-model` modifiers.
:::
2016-11-10 21:46:55 +08:00
### Basic usage
2017-12-12 12:45:09 +08:00
:::demo
2016-11-10 21:46:55 +08:00
```html
2016-12-28 18:33:45 +08:00
< el-input placeholder = "Please input" v-model = "input" > < / el-input >
2016-11-14 18:10:52 +08:00
< script >
export default {
data() {
return {
input: ''
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
:::
### Disabled
2017-12-12 12:45:09 +08:00
:::demo Disable the Input with the `disabled` attribute.
2016-11-10 21:46:55 +08:00
```html
< el-input
placeholder="Please input"
v-model="input1"
:disabled="true">
< / el-input >
2016-11-14 18:10:52 +08:00
< script >
export default {
data() {
return {
input1: ''
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
:::
2017-11-27 10:55:26 +08:00
### Clearable
2017-12-12 12:45:09 +08:00
:::demo Make the Input clearable with the `clearable` attribute.
2017-11-27 10:55:26 +08:00
```html
< el-input
placeholder="Please input"
v-model="input10"
clearable>
< / el-input >
< script >
export default {
data() {
return {
input10: ''
}
}
}
< / script >
```
:::
2019-02-22 16:40:35 +08:00
### Password box
:::demo Make a toggleable password Input with the `show-password` attribute.
```html
< el-input placeholder = "Please input password" v-model = "input11" show-password > < / el-input >
< script >
export default {
data() {
return {
input11: ''
}
}
}
< / script >
```
:::
2016-11-10 21:46:55 +08:00
### Input with icon
Add an icon to indicate input type.
2017-12-12 12:45:09 +08:00
:::demo To add icons in Input, you can simply use `prefix-icon` and `suffix-icon` attributes. Also, the `prefix` and `suffix` named slots works as well.
2016-11-10 21:46:55 +08:00
```html
2017-09-13 11:40:36 +08:00
< div class = "demo-input-suffix" >
2017-09-22 17:46:34 +08:00
< span class = "demo-input-label" > Using attributes< / span >
2017-09-13 11:40:36 +08:00
< el-input
2017-09-19 22:35:57 +08:00
placeholder="Pick a date"
suffix-icon="el-icon-date"
2017-09-13 11:40:36 +08:00
v-model="input2">
< / el-input >
< el-input
2017-09-19 22:35:57 +08:00
placeholder="Type something"
prefix-icon="el-icon-search"
2017-09-13 11:40:36 +08:00
v-model="input21">
< / el-input >
< / div >
< div class = "demo-input-suffix" >
2017-09-22 17:46:34 +08:00
< span class = "demo-input-label" > Using slots< / span >
2017-09-13 11:40:36 +08:00
< el-input
2017-09-19 22:35:57 +08:00
placeholder="Pick a date"
2017-09-13 11:40:36 +08:00
v-model="input22">
< i slot = "suffix" class = "el-input__icon el-icon-date" > < / i >
< / el-input >
< el-input
2017-09-19 22:35:57 +08:00
placeholder="Type something"
2017-09-13 11:40:36 +08:00
v-model="input23">
< i slot = "prefix" class = "el-input__icon el-icon-search" > < / i >
< / el-input >
< / div >
2016-11-14 18:10:52 +08:00
2017-09-22 17:46:34 +08:00
< style >
.demo-input-label {
display: inline-block;
width: 130px;
}
< / style >
2016-11-14 18:10:52 +08:00
< script >
export default {
data() {
return {
2017-09-13 11:40:36 +08:00
input2: '',
input21: '',
input22: '',
input23: ''
2016-11-14 18:10:52 +08:00
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
:::
### Textarea
2017-01-06 01:16:49 +08:00
Resizable for entering multiple lines of text information. Add attribute `type="textarea"` to change `input` into native `textarea` .
2016-11-10 21:46:55 +08:00
2017-12-12 12:45:09 +08:00
:::demo Control the height by setting the `rows` prop.
2016-11-10 21:46:55 +08:00
```html
< el-input
type="textarea"
2017-01-06 01:16:49 +08:00
:rows="2"
2016-11-10 21:46:55 +08:00
placeholder="Please input"
v-model="textarea">
< / el-input >
2016-11-14 18:10:52 +08:00
< script >
export default {
data() {
return {
textarea: ''
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
2016-11-14 18:10:52 +08:00
:::
2017-01-06 01:16:49 +08:00
### Autosize Textarea
Setting the `autosize` prop for a textarea type of Input makes the height to automatically adjust based on the content. An options object can be provided to `autosize` to specify the minimum and maximum number of lines the textarea can automatically adjust.
2017-12-12 12:45:09 +08:00
:::demo
2017-01-06 01:16:49 +08:00
```html
< el-input
type="textarea"
autosize
placeholder="Please input"
v-model="textarea2">
< / el-input >
< div style = "margin: 20px 0;" > < / div >
< el-input
type="textarea"
:autosize="{ minRows: 2, maxRows: 4}"
placeholder="Please input"
v-model="textarea3">
< / el-input >
< script >
export default {
data() {
return {
textarea2: '',
textarea3: ''
}
}
}
< / script >
```
:::
2016-11-10 21:46:55 +08:00
### Mixed input
Prepend or append an element, generally a label or a button.
2017-12-12 12:45:09 +08:00
:::demo Use `slot` to distribute elements that prepend or append to Input.
2016-11-10 21:46:55 +08:00
```html
2016-12-28 18:33:45 +08:00
< div >
2017-01-16 02:45:53 +08:00
< el-input placeholder = "Please input" v-model = "input3" >
2016-12-28 18:33:45 +08:00
< template slot = "prepend" > Http://< / template >
< / el-input >
< / div >
< div style = "margin-top: 15px;" >
2017-01-16 02:45:53 +08:00
< el-input placeholder = "Please input" v-model = "input4" >
2016-12-28 18:33:45 +08:00
< template slot = "append" > .com< / template >
< / el-input >
< / div >
< div style = "margin-top: 15px;" >
2017-10-25 11:58:58 +08:00
< el-input placeholder = "Please input" v-model = "input5" class = "input-with-select" >
2017-01-16 02:45:53 +08:00
< el-select v-model = "select" slot = "prepend" placeholder = "Select" >
< el-option label = "Restaurant" value = "1" > < / el-option >
< el-option label = "Order No." value = "2" > < / el-option >
< el-option label = "Tel" value = "3" > < / el-option >
2016-12-28 18:33:45 +08:00
< / el-select >
2017-10-12 16:07:50 +08:00
< el-button slot = "append" icon = "el-icon-search" > < / el-button >
2016-12-28 18:33:45 +08:00
< / el-input >
< / div >
2017-01-16 02:45:53 +08:00
2017-01-08 14:37:37 +08:00
< style >
.el-select .el-input {
width: 110px;
}
2017-10-25 11:58:58 +08:00
.input-with-select .el-input-group__prepend {
background-color: #fff ;
}
2017-01-08 14:37:37 +08:00
< / style >
2016-11-14 18:10:52 +08:00
< script >
export default {
data() {
return {
input3: '',
input4: '',
input5: '',
select: ''
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
:::
### Sizes
2017-12-12 12:45:09 +08:00
:::demo Add `size` attribute to change the size of Input. In addition to the default size, there are three other options: `large` , `small` and `mini` .
2016-11-10 21:46:55 +08:00
```html
2016-12-28 18:33:45 +08:00
< div class = "demo-input-size" >
2016-11-10 21:46:55 +08:00
< el-input
2017-01-16 02:45:53 +08:00
placeholder="Please Input"
2016-11-10 21:46:55 +08:00
v-model="input6">
< / el-input >
< el-input
2017-09-19 22:35:57 +08:00
size="medium"
2017-01-16 02:45:53 +08:00
placeholder="Please Input"
2016-11-10 21:46:55 +08:00
v-model="input7">
< / el-input >
< el-input
size="small"
2017-01-16 02:45:53 +08:00
placeholder="Please Input"
2016-11-10 21:46:55 +08:00
v-model="input8">
< / el-input >
< el-input
size="mini"
2017-01-16 02:45:53 +08:00
placeholder="Please Input"
2016-11-10 21:46:55 +08:00
v-model="input9">
< / el-input >
< / div >
2016-11-14 18:10:52 +08:00
< script >
export default {
data() {
return {
input6: '',
input7: '',
input8: '',
input9: ''
}
}
}
< / script >
2016-11-10 21:46:55 +08:00
```
:::
2016-12-29 20:34:03 +08:00
### Autocomplete
2016-11-10 21:46:55 +08:00
You can get some recommended tips based on the current input.
2017-12-12 12:45:09 +08:00
:::demo Autocomplete component provides input suggestions. The `fetch-suggestions` attribute is a method that returns suggested input. In this example, `querySearch(queryString, cb)` returns suggestions to Autocomplete via `cb(data)` when suggestions are ready.
2016-11-10 21:46:55 +08:00
```html
2016-12-28 18:33:45 +08:00
< el-row class = "demo-autocomplete" >
< el-col :span = "12" >
2017-01-16 02:45:53 +08:00
< div class = "sub-title" > list suggestions when activated< / div >
2016-11-10 21:46:55 +08:00
< el-autocomplete
2016-11-26 02:32:02 +08:00
class="inline-input"
2016-11-10 21:46:55 +08:00
v-model="state1"
:fetch-suggestions="querySearch"
2017-01-16 02:45:53 +08:00
placeholder="Please Input"
2016-11-10 21:46:55 +08:00
@select ="handleSelect"
>< / el-autocomplete >
< / el-col >
2016-12-28 18:33:45 +08:00
< el-col :span = "12" >
2017-01-16 02:45:53 +08:00
< div class = "sub-title" > list suggestions on input< / div >
2016-11-10 21:46:55 +08:00
< el-autocomplete
2016-11-26 02:32:02 +08:00
class="inline-input"
2016-11-10 21:46:55 +08:00
v-model="state2"
:fetch-suggestions="querySearch"
2017-01-16 02:45:53 +08:00
placeholder="Please Input"
2016-11-10 21:46:55 +08:00
:trigger-on-focus="false"
@select ="handleSelect"
>< / el-autocomplete >
< / el-col >
< / el-row >
< script >
export default {
data() {
return {
links: [],
state1: '',
state2: ''
};
},
methods: {
querySearch(queryString, cb) {
var links = this.links;
var results = queryString ? links.filter(this.createFilter(queryString)) : links;
// call callback function to return suggestions
cb(results);
},
createFilter(queryString) {
return (link) => {
2017-10-20 14:03:34 +08:00
return (link.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
2016-11-10 21:46:55 +08:00
};
},
loadAll() {
return [
{ "value": "vue", "link": "https://github.com/vuejs/vue" },
{ "value": "element", "link": "https://github.com/ElemeFE/element" },
{ "value": "cooking", "link": "https://github.com/ElemeFE/cooking" },
{ "value": "mint-ui", "link": "https://github.com/ElemeFE/mint-ui" },
{ "value": "vuex", "link": "https://github.com/vuejs/vuex" },
{ "value": "vue-router", "link": "https://github.com/vuejs/vue-router" },
{ "value": "babel", "link": "https://github.com/babel/babel" }
];
},
handleSelect(item) {
console.log(item);
}
},
mounted() {
this.links = this.loadAll();
}
}
< / script >
```
:::
### Custom template
Customize how suggestions are displayed.
2017-09-25 19:16:16 +08:00
:::demo Use `scoped slot` to customize suggestion items. In the scope, you can access the suggestion object via the `item` key.
2016-11-10 21:46:55 +08:00
```html
< el-autocomplete
2016-12-29 20:34:03 +08:00
popper-class="my-autocomplete"
2016-11-10 21:46:55 +08:00
v-model="state3"
:fetch-suggestions="querySearch"
placeholder="Please input"
2017-10-18 18:31:03 +08:00
@select ="handleSelect">
< i
class="el-icon-edit el-input__icon"
slot="suffix"
@click ="handleIconClick">
< / i >
2018-04-05 21:25:14 +08:00
< template slot-scope = "{ item }" >
< div class = "value" > {{ item.value }}< / div >
< span class = "link" > {{ item.link }}< / span >
2017-09-25 19:16:16 +08:00
< / template >
< / el-autocomplete >
2016-11-10 21:46:55 +08:00
2016-11-14 18:10:52 +08:00
< style >
.my-autocomplete {
li {
line-height: normal;
padding: 7px;
.value {
text-overflow: ellipsis;
overflow: hidden;
}
.link {
font-size: 12px;
color: #b4b4b4 ;
}
}
}
< / style >
2016-11-10 21:46:55 +08:00
< script >
export default {
data() {
return {
links: [],
state3: ''
};
},
methods: {
querySearch(queryString, cb) {
var links = this.links;
2018-01-13 20:19:04 +08:00
var results = queryString ? links.filter(this.createFilter(queryString)) : links;
2017-09-25 19:16:16 +08:00
// call callback function to return suggestion objects
2016-11-10 21:46:55 +08:00
cb(results);
},
createFilter(queryString) {
return (link) => {
2017-10-20 14:03:34 +08:00
return (link.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
2016-11-10 21:46:55 +08:00
};
},
loadAll() {
return [
{ "value": "vue", "link": "https://github.com/vuejs/vue" },
{ "value": "element", "link": "https://github.com/ElemeFE/element" },
{ "value": "cooking", "link": "https://github.com/ElemeFE/cooking" },
{ "value": "mint-ui", "link": "https://github.com/ElemeFE/mint-ui" },
{ "value": "vuex", "link": "https://github.com/vuejs/vuex" },
{ "value": "vue-router", "link": "https://github.com/vuejs/vue-router" },
{ "value": "babel", "link": "https://github.com/babel/babel" }
];
},
handleSelect(item) {
console.log(item);
2017-02-12 13:14:04 +08:00
},
handleIconClick(ev) {
console.log(ev);
2016-11-10 21:46:55 +08:00
}
},
mounted() {
this.links = this.loadAll();
}
}
< / script >
```
:::
### Remote search
Search data from server-side.
2017-12-12 12:45:09 +08:00
:::demo
2016-11-10 21:46:55 +08:00
```html
< el-autocomplete
v-model="state4"
:fetch-suggestions="querySearchAsync"
placeholder="Please input"
@select ="handleSelect"
>< / el-autocomplete >
< script >
export default {
data() {
return {
links: [],
state4: '',
timeout: null
};
},
methods: {
loadAll() {
return [
{ "value": "vue", "link": "https://github.com/vuejs/vue" },
{ "value": "element", "link": "https://github.com/ElemeFE/element" },
{ "value": "cooking", "link": "https://github.com/ElemeFE/cooking" },
{ "value": "mint-ui", "link": "https://github.com/ElemeFE/mint-ui" },
{ "value": "vuex", "link": "https://github.com/vuejs/vuex" },
{ "value": "vue-router", "link": "https://github.com/vuejs/vue-router" },
{ "value": "babel", "link": "https://github.com/babel/babel" }
];
},
querySearchAsync(queryString, cb) {
var links = this.links;
var results = queryString ? links.filter(this.createFilter(queryString)) : links;
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
cb(results);
}, 3000 * Math.random());
},
createFilter(queryString) {
return (link) => {
2017-10-20 14:03:34 +08:00
return (link.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
2016-11-10 21:46:55 +08:00
};
},
handleSelect(item) {
console.log(item);
}
},
mounted() {
this.links = this.loadAll();
}
};
< / script >
```
:::
2016-11-14 18:10:52 +08:00
### Input Attributes
2016-11-10 21:46:55 +08:00
| Attribute | Description | Type | Accepted Values | Default |
| ----| ----| ----| ---- | ----- |
2018-04-29 12:01:08 +08:00
|type| type of input | string | text, textarea and other [native input types ](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types ) | text |
2019-01-23 11:34:19 +08:00
|value / v-model| binding value | string / number| — | — |
2018-03-10 20:43:18 +08:00
|maxlength| same as `maxlength` in native input | number| — | — |
|minlength| same as `minlength` in native input | number | — | — |
2016-11-10 21:46:55 +08:00
|placeholder| placeholder of Input| string | — | — |
2017-11-30 13:21:16 +08:00
| clearable | whether to show clear button | boolean | — | false |
2019-02-22 16:40:35 +08:00
| show-password | whether to show toggleable password input| boolean | — | false |
2016-11-10 21:46:55 +08:00
|disabled | whether Input is disabled | boolean | — | false |
2017-10-18 18:31:03 +08:00
|size | size of Input, works when `type` is not 'textarea' | string | medium / small / mini | — |
2017-09-19 22:35:57 +08:00
| prefix-icon | prefix icon class | string | — | — |
| suffix-icon | suffix icon class | string | — | — |
2016-11-10 21:46:55 +08:00
|rows | number of rows of textarea, only works when `type` is 'textarea' | number | — | 2 |
2017-10-18 18:31:03 +08:00
|autosize | whether textarea has an adaptive height, only works when `type` is 'textarea'. Can accept an object, e.g. { minRows: 2, maxRows: 6 } | boolean / object | — | false |
2018-08-28 15:44:21 +08:00
|autocomplete | same as `autocomplete` in native input | string | on/off | off |
|auto-complete | @DEPRECATED in next major version | string | on/off | off |
2016-11-10 21:46:55 +08:00
|name | same as `name` in native input | string | — | — |
2017-02-08 11:49:54 +08:00
| readonly | same as `readonly` in native input | boolean | — | false |
2017-02-21 10:43:56 +08:00
|max | same as `max` in native input | — | — | — |
|min | same as `min` in native input | — | — | — |
|step| same as `step` in native input | — | — | — |
2017-01-06 16:52:45 +08:00
|resize| control the resizability | string | none, both, horizontal, vertical | — |
2016-11-10 21:46:55 +08:00
|autofocus | same as `autofocus` in native input | boolean | — | false |
|form | same as `form` in native input | string | — | — |
2017-09-29 15:58:07 +08:00
| label | label text | string | — | — |
2017-12-28 10:58:47 +08:00
| tabindex | input tabindex | string | - | - |
2018-11-22 18:29:16 +08:00
| validate-event | whether to trigger form validation | boolean | - | true |
2017-10-18 18:31:03 +08:00
### Input slots
2017-09-19 22:35:57 +08:00
| Name | Description |
|------|--------|
2017-11-17 12:36:42 +08:00
| prefix | content as Input prefix, only works when `type` is 'text' |
| suffix | content as Input suffix, only works when `type` is 'text' |
| prepend | content to prepend before Input, only works when `type` is 'text' |
| append | content to append after Input, only works when `type` is 'text' |
2017-09-19 22:35:57 +08:00
2016-11-10 21:46:55 +08:00
### Input Events
| Event Name | Description | Parameters |
|----| ----| ----|
2017-07-18 12:09:03 +08:00
| blur | triggers when Input blurs | (event: Event) |
| focus | triggers when Input focuses | (event: Event) |
2016-12-26 23:01:46 +08:00
| change | triggers when the icon inside Input value change | (value: string \| number) |
2018-04-19 16:07:03 +08:00
| clear | triggers when the Input is cleared by clicking the clear button | — |
2016-11-10 21:46:55 +08:00
2018-03-19 12:17:57 +08:00
### Input Methods
| Method | Description | Parameters |
|------|--------|-------|
| focus | focus the input element | — |
2018-03-26 10:51:18 +08:00
| blur | blur the input element | — |
2018-03-19 12:17:57 +08:00
| select | select the text in input element | — |
2016-11-14 18:10:52 +08:00
### Autocomplete Attributes
2016-11-10 21:46:55 +08:00
Attribute | Description | Type | Options | Default
|----| ----| ----| ---- | -----|
|placeholder| the placeholder of Autocomplete| string | — | — |
2018-11-13 18:33:33 +08:00
| clearable | whether to show clear button | boolean | — | false |
2016-11-10 21:46:55 +08:00
|disabled | whether Autocomplete is disabled | boolean | — | false|
2018-02-04 14:36:50 +08:00
| value-key | key name of the input suggestion object for display | string | — | value |
2017-02-12 13:14:04 +08:00
|icon | icon name | string | — | — |
2016-11-10 21:46:55 +08:00
|value | binding value | string | — | — |
2017-10-10 18:06:01 +08:00
| debounce | debounce delay when typing, in milliseconds | number | — | 300 |
2018-03-30 14:42:23 +08:00
| placement | placement of the popup menu | string | top / top-start / top-end / bottom / bottom-start / bottom-end | bottom-start |
2016-11-10 21:46:55 +08:00
|fetch-suggestions | a method to fetch input suggestions. When suggestions are ready, invoke `callback(data:[])` to return them to Autocomplete | Function(queryString, callback) | — | — |
2016-12-29 20:34:03 +08:00
| popper-class | custom class name for autocomplete's dropdown | string | — | — |
2017-01-06 12:00:52 +08:00
| trigger-on-focus | whether show suggestions when input focus | boolean | — | true |
2017-09-20 12:23:38 +08:00
| name | same as `name` in native input | string | — | — |
2017-09-15 12:16:45 +08:00
| select-when-unmatched | whether to emit a `select` event on enter when there is no autocomplete match | boolean | — | false |
2017-09-29 15:58:07 +08:00
| label | label text | string | — | — |
2017-11-24 10:26:14 +08:00
| prefix-icon | prefix icon class | string | — | — |
| suffix-icon | suffix icon class | string | — | — |
2018-05-21 17:27:42 +08:00
| hide-loading | whether to hide the loading icon in remote search | boolean | — | false |
2018-08-06 19:14:16 +08:00
| popper-append-to-body | whether to append the dropdown to body. If the positioning of the dropdown is wrong, you can try to set this prop to false | boolean | - | true |
2019-02-14 20:05:42 +08:00
| highlight-first-item | whether to highlight first item in remote search suggestions by default | boolean | — | false |
2017-10-18 18:31:03 +08:00
2018-04-05 21:25:14 +08:00
### Autocomplete Slots
2017-10-18 18:31:03 +08:00
| Name | Description |
|------|--------|
| prefix | content as Input prefix |
| suffix | content as Input suffix |
| prepend | content to prepend before Input |
| append | content to append after Input |
2018-04-05 21:25:14 +08:00
### Autocomplete Scoped Slot
| Name | Description |
|------|--------|
| — | Custom content for input suggestions. The scope parameter is { item } |
2016-11-10 21:46:55 +08:00
### Autocomplete Events
| Event Name | Description | Parameters |
|----| ----| ----|
|select | triggers when a suggestion is clicked | suggestion being clicked |
2018-03-19 12:17:57 +08:00
### Autocomplete Methods
2017-07-18 13:47:35 +08:00
| Method | Description | Parameters |
|------|--------|-------|
2018-03-19 12:17:57 +08:00
| focus | focus the input element | — |