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
bb58f007
Commit
bb58f007
authored
Aug 09, 2017
by
Leopoldthecoder
Committed by
杨奕
Aug 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slider: change event only triggers on user input
parent
a1324324
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
3 deletions
+48
-3
packages/slider/src/button.vue
packages/slider/src/button.vue
+7
-1
packages/slider/src/main.vue
packages/slider/src/main.vue
+8
-2
test/unit/specs/slider.spec.js
test/unit/specs/slider.spec.js
+33
-0
No files found.
packages/slider/src/button.vue
View file @
bb58f007
...
...
@@ -39,6 +39,7 @@
return
{
hovering
:
false
,
dragging
:
false
,
isClick
:
false
,
startX
:
0
,
currentX
:
0
,
startY
:
0
,
...
...
@@ -127,6 +128,7 @@
onDragStart
(
event
)
{
this
.
dragging
=
true
;
this
.
isClick
=
true
;
if
(
this
.
vertical
)
{
this
.
startY
=
event
.
clientY
;
}
else
{
...
...
@@ -137,6 +139,7 @@
onDragging
(
event
)
{
if
(
this
.
dragging
)
{
this
.
isClick
=
false
;
this
.
displayTooltip
();
let
diff
=
0
;
if
(
this
.
vertical
)
{
...
...
@@ -160,7 +163,10 @@
setTimeout
(()
=>
{
this
.
dragging
=
false
;
this
.
hideTooltip
();
this
.
setPosition
(
this
.
newPosition
);
if
(
!
this
.
isClick
)
{
this
.
setPosition
(
this
.
newPosition
);
this
.
$parent
.
emitChange
();
}
},
0
);
window
.
removeEventListener
(
'
mousemove
'
,
this
.
onDragging
);
window
.
removeEventListener
(
'
mouseup
'
,
this
.
onDragEnd
);
...
...
packages/slider/src/main.vue
View file @
bb58f007
...
...
@@ -6,6 +6,7 @@
v-if=
"showInput && !range"
class=
"el-slider__input"
ref=
"input"
@
change=
"$nextTick(emitChange)"
:step=
"step"
:disabled=
"disabled"
:controls=
"showInputControls"
...
...
@@ -183,7 +184,6 @@
this
.
firstValue
=
val
[
0
];
this
.
secondValue
=
val
[
1
];
if
(
this
.
valueChanged
())
{
this
.
$emit
(
'
change
'
,
[
this
.
minValue
,
this
.
maxValue
]);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.change
'
,
[
this
.
minValue
,
this
.
maxValue
]);
this
.
oldValue
=
val
.
slice
();
}
...
...
@@ -196,7 +196,6 @@
}
else
{
this
.
firstValue
=
val
;
if
(
this
.
valueChanged
())
{
this
.
$emit
(
'
change
'
,
val
);
this
.
dispatch
(
'
ElFormItem
'
,
'
el.form.change
'
,
val
);
this
.
oldValue
=
val
;
}
...
...
@@ -228,12 +227,19 @@
const
sliderOffsetLeft
=
this
.
$refs
.
slider
.
getBoundingClientRect
().
left
;
this
.
setPosition
((
event
.
clientX
-
sliderOffsetLeft
)
/
this
.
sliderSize
*
100
);
}
this
.
emitChange
();
},
resetSize
()
{
if
(
this
.
$refs
.
slider
)
{
this
.
sliderSize
=
this
.
$refs
.
slider
[
`client
${
this
.
vertical
?
'
Height
'
:
'
Width
'
}
`
];
}
},
emitChange
()
{
this
.
$nextTick
(()
=>
{
this
.
$emit
(
'
change
'
,
this
.
range
?
[
this
.
minValue
,
this
.
maxValue
]
:
this
.
value
);
});
}
},
...
...
test/unit/specs/slider.spec.js
View file @
bb58f007
...
...
@@ -180,6 +180,39 @@ describe('Slider', () => {
},
10
);
});
it
(
'
change event
'
,
done
=>
{
vm
=
createVue
({
template
:
`
<div>
<el-slider v-model="value" @change="onChange">
</el-slider>
</div>
`
,
data
()
{
return
{
data
:
0
,
value
:
0
};
},
methods
:
{
onChange
(
val
)
{
this
.
data
=
val
;
}
}
},
true
);
const
slider
=
vm
.
$children
[
0
];
vm
.
value
=
10
;
setTimeout
(()
=>
{
expect
(
vm
.
data
).
to
.
equal
(
0
);
slider
.
onSliderClick
({
clientX
:
100
});
setTimeout
(()
=>
{
expect
(
vm
.
data
>
0
).
to
.
true
;
done
();
},
10
);
},
10
);
});
it
(
'
disabled
'
,
done
=>
{
vm
=
createVue
({
template
:
`
...
...
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