fix(slider): empty range value (#9409)

* fix: slider empty range value

* fix: update slider default range value
This commit is contained in:
Aex 2021-09-11 16:48:52 +08:00 committed by GitHub
parent 51b326fcdb
commit 5b8f1d9be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,17 +130,17 @@ export default defineComponent({
const isSameValue = (newValue: SliderValue, oldValue: SliderValue) =>
JSON.stringify(newValue) === JSON.stringify(oldValue);
// 处理两个滑块重叠之后的情况
const handleOverlap = (value: NumberRange) => {
if (value[0] > value[1]) {
return value.slice(0).reverse();
}
return value;
const handleRangeValue = (value: NumberRange) => {
// 设置默认值
const left = value[0] ?? Number(props.min);
const right = value[1] ?? Number(props.max);
// 处理两个滑块重叠之后的情况
return left > right ? [right, left] : [left, right];
};
const updateValue = (value: SliderValue, end?: boolean) => {
if (isRange(value)) {
value = handleOverlap(value).map(format) as NumberRange;
value = handleRangeValue(value).map(format) as NumberRange;
} else {
value = format(value);
}