diff --git a/examples/sites/demos/pc/app/slider/basic-usage-composition-api.vue b/examples/sites/demos/pc/app/slider/basic-usage-composition-api.vue
index 760b787e6..91ed87a95 100644
--- a/examples/sites/demos/pc/app/slider/basic-usage-composition-api.vue
+++ b/examples/sites/demos/pc/app/slider/basic-usage-composition-api.vue
@@ -1,7 +1,7 @@
设置值
-
+
diff --git a/examples/sites/demos/pc/app/slider/basic-usage.vue b/examples/sites/demos/pc/app/slider/basic-usage.vue
index e908ac837..c96fc93b9 100644
--- a/examples/sites/demos/pc/app/slider/basic-usage.vue
+++ b/examples/sites/demos/pc/app/slider/basic-usage.vue
@@ -1,7 +1,7 @@
设置值
-
+
diff --git a/packages/renderless/src/slider/vue.ts b/packages/renderless/src/slider/vue.ts
index f431e5180..0b8d71fb6 100644
--- a/packages/renderless/src/slider/vue.ts
+++ b/packages/renderless/src/slider/vue.ts
@@ -165,7 +165,16 @@ export const renderless = (
handleSlotInput: handleSlotInput(state)
})
- watch(() => props.modelValue, api.watchModelValue, { immediate: true })
+ watch(
+ () => props.modelValue,
+ (value) => {
+ if (props.max < props.min) {
+ throw new Error('Slider min should not be greater than max.')
+ }
+ api.watchModelValue(value)
+ },
+ { immediate: true }
+ )
watch(() => state.activeValue, api.watchActiveValue, { immediate: true })
watch(
diff --git a/packages/vue/src/slider/__tests__/slider.test.tsx b/packages/vue/src/slider/__tests__/slider.test.tsx
index 1c4d9c6e1..297f414f1 100644
--- a/packages/vue/src/slider/__tests__/slider.test.tsx
+++ b/packages/vue/src/slider/__tests__/slider.test.tsx
@@ -1,7 +1,7 @@
import { mountPcMode } from '@opentiny-internal/vue-test-utils'
import { describe, expect, test, vi } from 'vitest'
import Slider from '@opentiny/vue-slider'
-import { nextTick } from 'vue'
+import { nextTick, ref } from 'vue'
let value = 40
@@ -18,9 +18,37 @@ describe('PC Mode', () => {
test.todo('disabled 是否禁用')
- test.todo('min 设置最小值。')
+ test('min 设置最小值。', async () => {
+ const value = ref(60)
+ mount(() => )
- test.todo('max 设置最大值。必需是整数,可以负数。必需大于所设置的最小值。')
+ await nextTick()
+ value.value = 40
+ await nextTick()
+ expect(value.value).toBe(50)
+ value.value = 120
+ await nextTick()
+ expect(value.value).toBe(100)
+ })
+
+ test('max 设置最大值。必需是整数,可以负数。必需大于所设置的最小值。', async () => {
+ const value = ref(60)
+
+ mount(() => )
+
+ await nextTick()
+ expect(value.value).toBe(-5)
+ })
+
+ test('min 大于 max的时候报错', async () => {
+ try {
+ const value = ref(60)
+ mount(() => )
+ } catch (error) {
+ expect(error).to.be.an('error')
+ expect(error.message).to.equal('Slider min should not be greater than max.')
+ }
+ })
test.todo('step 设置滑块移动时,每步位移距离,必需是大于0的正整数。')
@@ -48,8 +76,7 @@ describe('PC Mode', () => {
show-input={true}
v-slots={{
default: (slotScope) => {slotScope.slotScope}%
- }}
- >
+ }}>
))
expect(wrapper.find('.onlyText').text()).toBe(`${value}%`)
})