Skip to content

Commit 63122f5

Browse files
committed
feat: update slider to 8.6.4
1 parent c36f435 commit 63122f5

File tree

7 files changed

+53
-16
lines changed

7 files changed

+53
-16
lines changed

components/vc-slider/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// base rc-slider 8.6.3
1+
// base rc-slider 8.6.4
22
import Slider from './src/'
33
export default Slider

components/vc-slider/src/Range.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const rangeProps = {
1818
disabled: PropTypes.bool,
1919
tabIndex: PropTypes.arrayOf(PropTypes.number),
2020
prefixCls: PropTypes.string,
21+
min: PropTypes.number,
22+
max: PropTypes.number,
2123
}
2224
const Range = {
2325
name: 'Range',
@@ -76,7 +78,7 @@ const Range = {
7678

7779
this.setState({ bounds: nextBounds })
7880

79-
if (bounds.some(v => utils.isValueOutOfRange(v, minAmaxProps))) {
81+
if (value.some(v => utils.isValueOutOfRange(v, minAmaxProps))) {
8082
const newValues = value.map((v) => {
8183
return utils.ensureValueInRange(v, minAmaxProps)
8284
})
@@ -118,7 +120,7 @@ const Range = {
118120
this.onChange({ bounds: nextBounds })
119121
},
120122
onEnd () {
121-
this.setState({ sHandle: null }, this.blur)
123+
this.setState({ sHandle: null })
122124
this.removeDocumentEvents()
123125
this.$emit('afterChange', this.bounds)
124126
},

components/vc-slider/src/Slider.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ const Slider = {
1515
disabled: PropTypes.bool,
1616
autoFocus: PropTypes.bool,
1717
tabIndex: PropTypes.number,
18+
min: PropTypes.number,
19+
max: PropTypes.number,
1820
},
1921
data () {
2022
const defaultValue = this.defaultValue !== undefined
2123
? this.defaultValue : this.min
2224
const value = this.value !== undefined
2325
? this.value : defaultValue
2426

25-
if (process.env.NODE_ENV !== 'production') {
27+
if (utils.isDev()) {
2628
warning(
2729
!hasProp(this, 'minimumTrackStyle'),
2830
'minimumTrackStyle will be deprecate, please use trackStyle instead.'
@@ -134,6 +136,9 @@ const Slider = {
134136
return this.sValue
135137
},
136138
trimAlignValue (v, nextProps = {}) {
139+
if (v === null) {
140+
return null
141+
}
137142
const mergedProps = { ...this.$props, ...nextProps }
138143
const val = utils.ensureValueInRange(v, mergedProps)
139144
return utils.ensureValuePrecision(val, mergedProps)

components/vc-slider/src/common/Steps.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const calcPoints = (vertical, marks, dots, step, min, max) => {
66
dots ? step > 0 : true,
77
'`Slider[step]` should be a positive number in order to make Slider[dots] work.'
88
)
9-
const points = Object.keys(marks).map(parseFloat)
9+
const points = Object.keys(marks).map(parseFloat).sort((a, b) => a - b)
1010
if (dots) {
1111
for (let i = min; i <= max; i += step) {
1212
if (points.indexOf(i) === -1) {
@@ -19,7 +19,7 @@ const calcPoints = (vertical, marks, dots, step, min, max) => {
1919

2020
const Steps = {
2121
functional: true,
22-
render (createElement, context) {
22+
render (h, context) {
2323
const { prefixCls, vertical, marks, dots, step, included,
2424
lowerBound, upperBound, max, min, dotStyle, activeDotStyle } = context.props
2525
const range = max - min

components/vc-slider/src/common/createSlider.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ export default function createSlider (Component) {
6969
activeDotStyle: {},
7070
}),
7171
data () {
72-
if (process.env.NODE_ENV !== 'production') {
72+
if (utils.isDev()) {
7373
const { step, max, min } = this
74+
const isPointDiffEven = isFinite(max - min) ? (max - min) % step === 0 : true; // eslint-disable-line
7475
warning(
75-
step && Math.floor(step) === step ? (max - min) % step === 0 : true,
76+
step && Math.floor(step) === step ? isPointDiffEven : true,
7677
'Slider[max] - Slider[min] (%s) should be a multiple of Slider[step] (%s)',
7778
max - min,
7879
step
@@ -108,6 +109,9 @@ export default function createSlider (Component) {
108109
methods: {
109110
defaultHandle ({ index, ref, className, style, ...restProps }) {
110111
delete restProps.dragging
112+
if (restProps.value === null) {
113+
return null
114+
}
111115
const handleProps = {
112116
props: {
113117
...restProps,
@@ -195,12 +199,13 @@ export default function createSlider (Component) {
195199
onClickMarkLabel (e, value) {
196200
e.stopPropagation()
197201
this.onChange({ value })
202+
this.onEnd()
198203
},
199204
getSliderStart () {
200205
const slider = this.$refs.sliderRef
201206
const rect = slider.getBoundingClientRect()
202207

203-
return this.vertical ? rect.top : rect.left
208+
return this.vertical ? rect.top : (rect.left + window.pageXOffset)
204209
},
205210
getSliderLength () {
206211
const slider = this.$refs.sliderRef

components/vc-slider/src/utils.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import keyCode from '../../_util/KeyCode'
22

3+
export function isDev () {
4+
return (process.env.NODE_ENV !== 'production')
5+
}
6+
37
export function isEventFromHandle (e, handles) {
4-
return Object.keys(handles)
5-
.some(key => e.target === handles[key].$el)
8+
try {
9+
return Object.keys(handles)
10+
.some(key => e.target === handles[key].$el)
11+
} catch (error) {
12+
return false
13+
}
614
}
715

816
export function isValueOutOfRange (value, { min, max }) {
@@ -54,7 +62,7 @@ export function getHandleCenterPosition (vertical, handle) {
5462
const coords = handle.getBoundingClientRect()
5563
return vertical
5664
? coords.top + (coords.height * 0.5)
57-
: coords.left + (coords.width * 0.5)
65+
: window.pageXOffset + coords.left + (coords.width * 0.5)
5866
}
5967

6068
export function ensureValueInRange (val, { max, min }) {
@@ -69,7 +77,7 @@ export function ensureValueInRange (val, { max, min }) {
6977

7078
export function ensureValuePrecision (val, props) {
7179
const { step } = props
72-
const closestPoint = getClosestPoint(val, props)
80+
const closestPoint = isFinite(getClosestPoint(val, props)) ? getClosestPoint(val, props) : 0; // eslint-disable-line
7381
return step === null ? closestPoint
7482
: parseFloat(closestPoint.toFixed(getPrecision(step)))
7583
}
@@ -79,15 +87,32 @@ export function pauseEvent (e) {
7987
e.preventDefault()
8088
}
8189

90+
export function calculateNextValue (func, value, props) {
91+
const operations = {
92+
increase: (a, b) => a + b,
93+
decrease: (a, b) => a - b,
94+
}
95+
96+
const indexToGet = operations[func](Object.keys(props.marks).indexOf(JSON.stringify(value)), 1)
97+
const keyToGet = Object.keys(props.marks)[indexToGet]
98+
99+
if (props.step) {
100+
return operations[func](value, props.step)
101+
} else if (!!Object.keys(props.marks).length && !!props.marks[keyToGet]) {
102+
return props.marks[keyToGet]
103+
}
104+
return value
105+
}
106+
82107
export function getKeyboardValueMutator (e) {
83108
switch (e.keyCode) {
84109
case keyCode.UP:
85110
case keyCode.RIGHT:
86-
return (value, props) => value + props.step
111+
return (value, props) => calculateNextValue('increase', value, props)
87112

88113
case keyCode.DOWN:
89114
case keyCode.LEFT:
90-
return (value, props) => value - props.step
115+
return (value, props) => calculateNextValue('decrease', value, props)
91116

92117
case keyCode.END: return (value, props) => props.max
93118
case keyCode.HOME: return (value, props) => props.min

components/vc-steps/Step.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
itemWidth: PropTypes.string,
1515
status: PropTypes.string,
1616
iconPrefix: PropTypes.string,
17-
icon: PropTypes.node,
17+
icon: PropTypes.any,
1818
adjustMarginRight: PropTypes.string,
1919
stepNumber: PropTypes.string,
2020
description: PropTypes.any,

0 commit comments

Comments
 (0)