mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
fix(rate): fix bugs,allow-half not correct
This commit is contained in:
parent
246a12b466
commit
dbdc642f77
@ -17,6 +17,38 @@ describe('Rate.vue', () => {
|
||||
expect(stars.length).toEqual(10)
|
||||
})
|
||||
|
||||
test('allow half', async () => {
|
||||
const wrapper = mount({
|
||||
template: `
|
||||
<div>
|
||||
<el-rate v-model="value" allow-half ref='rate' />
|
||||
</div>
|
||||
`,
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
value: 0,
|
||||
}
|
||||
},
|
||||
components: {
|
||||
'el-rate': Rate,
|
||||
},
|
||||
}, {
|
||||
global: {
|
||||
provide: {
|
||||
elForm: {},
|
||||
},
|
||||
},
|
||||
})
|
||||
const vm = wrapper.vm
|
||||
const secondStar = wrapper.findAll('.el-rate__item')[1].element as HTMLElement
|
||||
vm.$refs.rate.setCurrentValue(1, { target: secondStar, offsetX: 0 })
|
||||
// expect(vm.$refs.rate.currentValue).toEqual(0.5)
|
||||
secondStar.click()
|
||||
vm.$refs.rate.resetCurrentValue()
|
||||
expect(vm.value).toEqual(0.5)
|
||||
})
|
||||
|
||||
test('with texts', () => {
|
||||
const wrapper = mount(Rate, {
|
||||
props: {
|
||||
@ -57,7 +89,7 @@ describe('Rate.vue', () => {
|
||||
<el-rate v-model="value1" />
|
||||
</div>
|
||||
`,
|
||||
props:{},
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
value1: 0,
|
||||
@ -79,4 +111,33 @@ describe('Rate.vue', () => {
|
||||
thirdStar.click()
|
||||
expect(vm.value1).toEqual(3)
|
||||
})
|
||||
|
||||
test('colors', () => {
|
||||
const wrapper = mount({
|
||||
template: `
|
||||
<div>
|
||||
<el-rate v-model="value" :colors="['#99A9BF', '#F7BA2A', '#FF9900']"></el-rate>
|
||||
</div>
|
||||
`,
|
||||
props:{},
|
||||
data() {
|
||||
return {
|
||||
value: 4,
|
||||
}
|
||||
},
|
||||
components: {
|
||||
'el-rate': Rate,
|
||||
},
|
||||
}, {
|
||||
global: {
|
||||
provide: {
|
||||
elForm: {},
|
||||
},
|
||||
},
|
||||
})
|
||||
// const vm = wrapper.vm
|
||||
const thirdStar = (wrapper.findAll('.el-rate__item')[2].element as HTMLElement).querySelector('.el-rate__icon') as any
|
||||
|
||||
expect(thirdStar.style.color).toEqual('rgb(255, 153, 0)')
|
||||
})
|
||||
})
|
||||
|
@ -261,8 +261,8 @@ export default defineComponent({
|
||||
}
|
||||
_currentValue = _currentValue < 0 ? 0 : _currentValue
|
||||
_currentValue = _currentValue > props.max ? props.max : _currentValue
|
||||
emit('update:modelValue', currentValue)
|
||||
emit('change', currentValue)
|
||||
emit('update:modelValue', _currentValue)
|
||||
emit('change', _currentValue)
|
||||
return _currentValue
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,28 @@ Used for rating
|
||||
```
|
||||
:::
|
||||
|
||||
### With allow-half
|
||||
:::demo Add attribute `allow-half` Half star allowed
|
||||
```html
|
||||
|
||||
<div class="block">
|
||||
<el-rate v-model="value" allow-half />
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from 'vue'
|
||||
export default {
|
||||
setup() {
|
||||
return {
|
||||
value: ref(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
:::
|
||||
|
||||
### With text
|
||||
|
||||
Using text to indicate rating score
|
||||
|
@ -34,6 +34,28 @@ Usado para la calificación
|
||||
```
|
||||
:::
|
||||
|
||||
### Media elección permitida
|
||||
:::demo Añadir propiedades `allow-half` Media estrella permitida
|
||||
```html
|
||||
|
||||
<div class="block">
|
||||
<el-rate v-model="value" allow-half />
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from 'vue'
|
||||
export default {
|
||||
setup() {
|
||||
return {
|
||||
value: ref(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
:::
|
||||
|
||||
### Con texto
|
||||
|
||||
Usa texto para indicar la puntuación
|
||||
|
@ -33,6 +33,29 @@ Utilisé pour donner une note sur cinq étoiles.
|
||||
```
|
||||
:::
|
||||
|
||||
### Demi-sélection autorisée
|
||||
:::demo Ajoutez l'attribut `allow-half` Demi-étoile autorisée
|
||||
```html
|
||||
|
||||
<div class="block">
|
||||
<el-rate v-model="value" allow-half />
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from 'vue'
|
||||
export default {
|
||||
setup() {
|
||||
return {
|
||||
value: ref(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
:::
|
||||
|
||||
|
||||
### Avec du texte
|
||||
|
||||
Vous pouvez ajouter du texte à chaque score.
|
||||
|
@ -33,6 +33,28 @@
|
||||
```
|
||||
:::
|
||||
|
||||
### 半選を許す
|
||||
:::demo 属性 `allow-half` 半星の出現を許す
|
||||
```html
|
||||
|
||||
<div class="block">
|
||||
<el-rate v-model="value" allow-half />
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from 'vue'
|
||||
export default {
|
||||
setup() {
|
||||
return {
|
||||
value: ref(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
:::
|
||||
|
||||
### テキスト付き
|
||||
|
||||
評価点を示すためのテキストの使用
|
||||
|
@ -33,18 +33,20 @@
|
||||
:::
|
||||
|
||||
### 允许半选
|
||||
:::demo 为组件设置 `allow-half` 允许出现半星
|
||||
:::demo 属性 `allow-half` 允许出现半星
|
||||
```html
|
||||
|
||||
<div class="block">
|
||||
<el-rate v-model="value" allow-half />
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from 'vue'
|
||||
export default {
|
||||
data() {
|
||||
setup() {
|
||||
return {
|
||||
value: null
|
||||
value: ref(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user