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
1f6cafeb
Commit
1f6cafeb
authored
Nov 21, 2016
by
Furybean
Committed by
杨奕
Nov 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slider: fix can not drag when step < 1
parent
a65a62f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
12 deletions
+42
-12
packages/slider/src/main.vue
packages/slider/src/main.vue
+18
-12
test/unit/specs/slider.spec.js
test/unit/specs/slider.spec.js
+24
-0
No files found.
packages/slider/src/main.vue
View file @
1f6cafeb
...
...
@@ -84,6 +84,7 @@
data
()
{
return
{
precision
:
null
,
inputValue
:
null
,
timeout
:
null
,
hovering
:
false
,
...
...
@@ -136,9 +137,13 @@
setPosition
(
newPos
)
{
if
(
newPos
>=
0
&&
(
newPos
<=
100
))
{
var
lengthPerStep
=
100
/
((
this
.
max
-
this
.
min
)
/
this
.
step
);
var
steps
=
Math
.
round
(
newPos
/
lengthPerStep
);
this
.
$emit
(
'
input
'
,
Math
.
round
(
steps
*
lengthPerStep
*
(
this
.
max
-
this
.
min
)
*
0.01
+
this
.
min
));
const
lengthPerStep
=
100
/
((
this
.
max
-
this
.
min
)
/
this
.
step
);
const
steps
=
Math
.
round
(
newPos
/
lengthPerStep
);
let
value
=
steps
*
lengthPerStep
*
(
this
.
max
-
this
.
min
)
*
0.01
+
this
.
min
;
if
(
this
.
precision
)
{
value
=
parseFloat
(
value
.
toFixed
(
this
.
precision
));
}
this
.
$emit
(
'
input
'
,
value
);
this
.
currentPosition
=
(
this
.
value
-
this
.
min
)
/
(
this
.
max
-
this
.
min
)
*
100
+
'
%
'
;
if
(
!
this
.
dragging
)
{
if
(
this
.
value
!==
this
.
oldValue
)
{
...
...
@@ -151,10 +156,8 @@
onSliderClick
(
event
)
{
if
(
this
.
disabled
)
return
;
var
currentX
=
event
.
clientX
;
var
sliderOffsetLeft
=
this
.
$refs
.
slider
.
getBoundingClientRect
().
left
;
var
newPos
=
(
currentX
-
sliderOffsetLeft
)
/
this
.
$sliderWidth
*
100
;
this
.
setPosition
(
newPos
);
const
sliderOffsetLeft
=
this
.
$refs
.
slider
.
getBoundingClientRect
().
left
;
this
.
setPosition
((
event
.
clientX
-
sliderOffsetLeft
)
/
this
.
$sliderWidth
*
100
);
},
onInputChange
()
{
...
...
@@ -176,7 +179,7 @@
if
(
this
.
dragging
)
{
this
.
$refs
.
tooltip
.
showPopper
=
true
;
this
.
currentX
=
event
.
clientX
;
var
diff
=
(
this
.
currentX
-
this
.
startX
)
/
this
.
$sliderWidth
*
100
;
const
diff
=
(
this
.
currentX
-
this
.
startX
)
/
this
.
$sliderWidth
*
100
;
this
.
newPos
=
this
.
startPos
+
diff
;
this
.
setPosition
(
this
.
newPos
);
}
...
...
@@ -206,10 +209,10 @@
},
stops
()
{
le
t
stopCount
=
(
this
.
max
-
this
.
value
)
/
this
.
step
;
let
result
=
[]
;
let
currentLeft
=
parseFloat
(
this
.
currentPositio
n
);
let
stepWidth
=
100
*
this
.
step
/
(
this
.
max
-
this
.
min
)
;
cons
t
stopCount
=
(
this
.
max
-
this
.
value
)
/
this
.
step
;
const
currentLeft
=
parseFloat
(
this
.
currentPosition
)
;
const
stepWidth
=
100
*
this
.
step
/
(
this
.
max
-
this
.
mi
n
);
const
result
=
[]
;
for
(
let
i
=
1
;
i
<
stopCount
;
i
++
)
{
result
.
push
(
currentLeft
+
i
*
stepWidth
);
}
...
...
@@ -223,6 +226,9 @@
}
else
if
(
this
.
value
>
this
.
max
)
{
this
.
$emit
(
'
input
'
,
this
.
max
);
}
if
(
this
.
step
&&
this
.
step
<
1
)
{
this
.
precision
=
this
.
step
.
toPrecision
(
1
).
split
(
'
.
'
)[
1
].
length
;
}
this
.
inputValue
=
this
.
inputValue
||
this
.
value
;
}
};
...
...
test/unit/specs/slider.spec.js
View file @
1f6cafeb
...
...
@@ -86,6 +86,30 @@ describe('Slider', () => {
},
150
);
});
it
(
'
step
'
,
done
=>
{
vm
=
createVue
({
template
:
`
<div style="width: 200px;">
<el-slider v-model="value" :min="0" :max="1" :step="0.1"></el-slider>
</div>
`
,
data
()
{
return
{
value
:
0
};
}
},
true
);
const
slider
=
vm
.
$children
[
0
];
setTimeout
(()
=>
{
slider
.
onButtonDown
({
clientX
:
0
});
slider
.
onDragging
({
clientX
:
100
});
slider
.
onDragEnd
();
expect
(
vm
.
value
>
0.4
&&
vm
.
value
<
0.6
).
to
.
true
;
done
();
},
150
);
});
it
(
'
click
'
,
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