Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
6e428ffc
Commit
6e428ffc
authored
Dec 26, 2016
by
baiyaaaaa
Committed by
cinwell.li
Dec 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix input value binding bug (#1998)
* fix input value binding bug * improve input test & docs
parent
441f4c31
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
33 deletions
+94
-33
examples/docs/en-US/input.md
examples/docs/en-US/input.md
+4
-1
examples/docs/zh-CN/input.md
examples/docs/zh-CN/input.md
+4
-3
packages/input/src/input.vue
packages/input/src/input.vue
+32
-29
test/unit/specs/input.spec.js
test/unit/specs/input.spec.js
+54
-0
No files found.
examples/docs/en-US/input.md
View file @
6e428ffc
...
@@ -591,7 +591,10 @@ Search data from server-side.
...
@@ -591,7 +591,10 @@ Search data from server-side.
| Event Name | Description | Parameters |
| Event Name | Description | Parameters |
|----| ----| ----|
|----| ----| ----|
|click | triggers when the icon inside Input is clicked | event object |
|click | triggers when the icon inside Input is clicked | (event: Event) |
| blur | triggers when the icon inside Input is blur | (event: Event) |
| focus | triggers when the icon inside Input is focus | (event: Event) |
| change | triggers when the icon inside Input value change | (value: string
\|
number) |
### Autocomplete Attributes
### Autocomplete Attributes
...
...
examples/docs/zh-CN/input.md
View file @
6e428ffc
...
@@ -759,9 +759,10 @@ export default {
...
@@ -759,9 +759,10 @@ export default {
### Input Events
### Input Events
| 事件名称 | 说明 | 回调参数 |
| 事件名称 | 说明 | 回调参数 |
|---------|--------|---------|
|---------|--------|---------|
| click | 点击 Input 内的图标时触发 | event |
| click | 点击 Input 内的图标时触发 | (event: Event) |
| blur | 在 Input 失去焦点时触发 | event |
| blur | 在 Input 失去焦点时触发 | (event: Event) |
| focus | 在 Input 或得焦点时触发 | event |
| focus | 在 Input 或得焦点时触发 | (event: Event) |
| change | 在 Input 值改变时触发 | (value: string
\|
number) |
### Autocomplete Attributes
### Autocomplete Attributes
...
...
packages/input/src/input.vue
View file @
6e428ffc
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
:min=
"min"
:min=
"min"
:max=
"max"
:max=
"max"
:form=
"form"
:form=
"form"
:value=
"
v
alue"
:value=
"
currentV
alue"
ref=
"input"
ref=
"input"
@
input=
"handleInput"
@
input=
"handleInput"
@
focus=
"handleFocus"
@
focus=
"handleFocus"
...
@@ -76,6 +76,13 @@
...
@@ -76,6 +76,13 @@
mixins
:
[
emitter
],
mixins
:
[
emitter
],
data
()
{
return
{
currentValue
:
this
.
value
,
textareaStyle
:
{}
};
},
props
:
{
props
:
{
value
:
[
String
,
Number
],
value
:
[
String
,
Number
],
placeholder
:
String
,
placeholder
:
String
,
...
@@ -108,10 +115,23 @@
...
@@ -108,10 +115,23 @@
min
:
{}
min
:
{}
},
},
computed
:
{
validating
()
{
return
this
.
$parent
.
validateState
===
'
validating
'
;
}
},
watch
:
{
'
value
'
(
val
,
oldValue
)
{
this
.
setCurrentValue
(
val
);
}
},
methods
:
{
methods
:
{
handleBlur
(
event
)
{
handleBlur
(
event
)
{
this
.
$emit
(
'
blur
'
,
event
);
this
.
$emit
(
'
blur
'
,
event
);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.blur
'
,
[
this
.
currentValue
]);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.blur
'
,
[
this
.
currentValue
]);
this
.
currentValue
=
this
.
value
;
},
},
inputSelect
()
{
inputSelect
()
{
this
.
$refs
.
input
.
select
();
this
.
$refs
.
input
.
select
();
...
@@ -130,46 +150,29 @@
...
@@ -130,46 +150,29 @@
this
.
$emit
(
'
focus
'
,
event
);
this
.
$emit
(
'
focus
'
,
event
);
},
},
handleInput
(
event
)
{
handleInput
(
event
)
{
this
.
currentValue
=
event
.
target
.
value
;
this
.
setCurrentValue
(
event
.
target
.
value
)
;
},
},
handleIconClick
(
event
)
{
handleIconClick
(
event
)
{
this
.
$emit
(
'
click
'
,
event
);
this
.
$emit
(
'
click
'
,
event
);
},
setCurrentValue
(
value
)
{
if
(
value
===
this
.
currentValue
)
return
;
this
.
$nextTick
(
_
=>
{
this
.
resizeTextarea
();
});
this
.
currentValue
=
value
;
this
.
$emit
(
'
input
'
,
value
);
this
.
$emit
(
'
change
'
,
value
);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.change
'
,
[
value
]);
}
}
},
},
data
()
{
return
{
currentValue
:
this
.
value
,
textareaStyle
:
{}
};
},
created
()
{
created
()
{
this
.
$on
(
'
inputSelect
'
,
this
.
inputSelect
);
this
.
$on
(
'
inputSelect
'
,
this
.
inputSelect
);
},
},
mounted
()
{
mounted
()
{
this
.
resizeTextarea
();
this
.
resizeTextarea
();
},
computed
:
{
validating
()
{
return
this
.
$parent
.
validateState
===
'
validating
'
;
}
},
watch
:
{
'
value
'
(
val
,
oldValue
)
{
this
.
currentValue
=
val
;
},
'
currentValue
'
(
val
)
{
this
.
$nextTick
(
_
=>
{
this
.
resizeTextarea
();
});
this
.
$emit
(
'
input
'
,
val
);
this
.
$emit
(
'
change
'
,
val
);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.change
'
,
[
val
]);
}
}
}
};
};
</
script
>
</
script
>
test/unit/specs/input.spec.js
View file @
6e428ffc
...
@@ -104,6 +104,7 @@ describe('Input', () => {
...
@@ -104,6 +104,7 @@ describe('Input', () => {
},
true
);
},
true
);
expect
(
vm
.
$el
.
querySelector
(
'
.el-textarea__inner
'
).
getAttribute
(
'
rows
'
)).
to
.
be
.
equal
(
'
3
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.el-textarea__inner
'
).
getAttribute
(
'
rows
'
)).
to
.
be
.
equal
(
'
3
'
);
});
});
it
(
'
autosize
'
,
done
=>
{
it
(
'
autosize
'
,
done
=>
{
vm
=
createVue
({
vm
=
createVue
({
template
:
`
template
:
`
...
@@ -143,4 +144,57 @@ describe('Input', () => {
...
@@ -143,4 +144,57 @@ describe('Input', () => {
done
();
done
();
},
200
);
},
200
);
});
});
describe
(
'
Input Events
'
,
()
=>
{
it
(
'
event:focus & blur
'
,
done
=>
{
vm
=
createVue
({
template
:
`
<el-input
ref="input"
placeholder="请输入内容"
value="input">
</el-input>
`
},
true
);
const
spyFocus
=
sinon
.
spy
();
const
spyBlur
=
sinon
.
spy
();
vm
.
$refs
.
input
.
$on
(
'
focus
'
,
spyFocus
);
vm
.
$refs
.
input
.
$on
(
'
blur
'
,
spyBlur
);
vm
.
$el
.
querySelector
(
'
input
'
).
focus
();
vm
.
$el
.
querySelector
(
'
input
'
).
blur
();
vm
.
$nextTick
(
_
=>
{
expect
(
spyFocus
.
calledOnce
).
to
.
be
.
true
;
expect
(
spyBlur
.
calledOnce
).
to
.
be
.
true
;
done
();
});
});
it
(
'
event:change
'
,
done
=>
{
vm
=
createVue
({
template
:
`
<el-input
ref="input"
placeholder="请输入内容"
:value="input">
</el-input>
`
,
data
()
{
return
{
input
:
'
a
'
};
}
},
true
);
const
spy
=
sinon
.
spy
();
vm
.
$refs
.
input
.
$on
(
'
change
'
,
spy
);
vm
.
input
=
'
b
'
;
vm
.
$nextTick
(
_
=>
{
expect
(
spy
.
withArgs
(
'
b
'
).
calledOnce
).
to
.
be
.
true
;
done
();
});
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment