diff --git a/src/components/slider/slider.vue b/src/components/slider/slider.vue index bb591c1..6be36af 100644 --- a/src/components/slider/slider.vue +++ b/src/components/slider/slider.vue @@ -8,20 +8,44 @@ :value="exportValue[0]" :disabled="disabled" @on-change="handleInputChange"> -
+
-
+
- -
+ +
- -
+ +
@@ -110,7 +147,11 @@ startX: 0, currentX: 0, startPos: 0, - oldValue: val + oldValue: val, + valueIndex: { + min: 0, + max: 1, + }, }; }, watch: { @@ -173,7 +214,6 @@ return (val[1] - this.min) / this.valueRange * 100; }, barStyle () { - const style = { width: (this.currentValue[0] - this.min) / this.valueRange * 100 + '%' }; @@ -216,6 +256,30 @@ max = Math.min(this.max, max); return [min, max]; }, + getCurrentValue (event, type) { + if (this.disabled) { + return; + } + + const index = this.valueIndex[type]; + if (typeof index === 'undefined') { + return; + } + + return this.currentValue[index]; + }, + onKeyLeft (event, type) { + const value = this.getCurrentValue(event, type); + if (Number.isFinite(value)) { + this.changeButtonPosition(value - this.step, type); + } + }, + onKeyRight (event, type) { + const value = this.getCurrentValue(event, type); + if (Number.isFinite(value)) { + this.changeButtonPosition(value + this.step, type); + } + }, onPointerDown (event, type) { if (this.disabled) return; event.preventDefault(); diff --git a/src/styles/components/slider.less b/src/styles/components/slider.less index 4fa9e33..4b269a4 100644 --- a/src/styles/components/slider.less +++ b/src/styles/components/slider.less @@ -34,7 +34,9 @@ border-radius: 50%; background-color: #fff; transition: all @transition-time linear; + outline: 0; + &:focus, &:hover, &-dragging { -- libgit2 0.21.4