mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-26 03:16:35 +08:00
feat(Rate): add touchable prop (#4361)
This commit is contained in:
parent
a3b6744b24
commit
0bd3997373
@ -100,12 +100,13 @@ export default {
|
|||||||
| gutter | Icon gutter | *string \| number* | `4px` | - |
|
| gutter | Icon gutter | *string \| number* | `4px` | - |
|
||||||
| color | Selected color | *string* | `#ffd21e` | - |
|
| color | Selected color | *string* | `#ffd21e` | - |
|
||||||
| void-color | Void color | *string* | `#c7c7c7` | - |
|
| void-color | Void color | *string* | `#c7c7c7` | - |
|
||||||
|
| disabled-color | Disabled color | *string* | `#bdbdbd` | - |
|
||||||
| icon | Selected icon | *string* | `star` | - |
|
| icon | Selected icon | *string* | `star` | - |
|
||||||
| void-icon | Void icon | *string* | `star-o` | - |
|
| void-icon | Void icon | *string* | `star-o` | - |
|
||||||
| allow-half | Whether to allow half star | *boolean* | `false` | - |
|
| allow-half | Whether to allow half star | *boolean* | `false` | - |
|
||||||
| readonly | Whether to be readonly | *boolean* | `false` | - |
|
| readonly | Whether to be readonly | *boolean* | `false` | - |
|
||||||
| disabled | Whether to disable rate | *boolean* | `false` | - |
|
| disabled | Whether to disable rate | *boolean* | `false` | - |
|
||||||
| disabled-color | Disabled color | *string* | `#bdbdbd` | - |
|
| touchable | Whether to allow select rate by touch gesture | *boolean* | `true` | 2.2.0 |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -100,12 +100,13 @@ export default {
|
|||||||
| gutter | 图标间距,默认单位为`px` | *string \| number* | `4px` | - |
|
| gutter | 图标间距,默认单位为`px` | *string \| number* | `4px` | - |
|
||||||
| color | 选中时的颜色 | *string* | `#ffd21e` | - |
|
| color | 选中时的颜色 | *string* | `#ffd21e` | - |
|
||||||
| void-color | 未选中时的颜色 | *string* | `#c7c7c7` | - |
|
| void-color | 未选中时的颜色 | *string* | `#c7c7c7` | - |
|
||||||
|
| disabled-color | 禁用时的颜色 | *string* | `#bdbdbd` | - |
|
||||||
| icon | 选中时的图标名称或图片链接,可选值见 Icon 组件 | *string* | `star` | - |
|
| icon | 选中时的图标名称或图片链接,可选值见 Icon 组件 | *string* | `star` | - |
|
||||||
| void-icon | 未选中时的图标名称或图片链接,可选值见 Icon 组件 | *string* | `star-o` | - |
|
| void-icon | 未选中时的图标名称或图片链接,可选值见 Icon 组件 | *string* | `star-o` | - |
|
||||||
| allow-half | 是否允许半选 | *boolean* | `false` | - |
|
| allow-half | 是否允许半选 | *boolean* | `false` | - |
|
||||||
| readonly | 是否为只读状态 | *boolean* | `false` | - |
|
| readonly | 是否为只读状态 | *boolean* | `false` | - |
|
||||||
| disabled | 是否禁用评分 | *boolean* | `false` | - |
|
| disabled | 是否禁用评分 | *boolean* | `false` | - |
|
||||||
| disabled-color | 禁用时的颜色 | *string* | `#bdbdbd` | - |
|
| touchable | 是否可以通过滑动手势选择评分 | *boolean* | `true` | 2.2.0 |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -53,6 +53,10 @@ export default createComponent({
|
|||||||
count: {
|
count: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 5
|
default: 5
|
||||||
|
},
|
||||||
|
touchable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -84,7 +88,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTouchStart(event) {
|
onTouchStart(event) {
|
||||||
if (this.readonly || this.disabled) {
|
if (this.readonly || this.disabled || !this.touchable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +112,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTouchMove(event) {
|
onTouchMove(event) {
|
||||||
if (this.readonly || this.disabled) {
|
if (this.readonly || this.disabled || !this.touchable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,3 +137,18 @@ test('size prop', () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('untouchable', () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
const wrapper = mount(Rate, {
|
||||||
|
propsData: {
|
||||||
|
touchable: false
|
||||||
|
},
|
||||||
|
listeners: {
|
||||||
|
change: onChange
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
triggerDrag(wrapper, 100, 0);
|
||||||
|
expect(onChange).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
|
@ -132,7 +132,7 @@ export default {
|
|||||||
| duration | Animation duration (ms) | *number* | `500` | - |
|
| duration | Animation duration (ms) | *number* | `500` | - |
|
||||||
| loop | Whether to enable loop | *boolean* | `true` | - |
|
| loop | Whether to enable loop | *boolean* | `true` | - |
|
||||||
| vertical | Vertical Scrolling | *boolean* | `false` | - |
|
| vertical | Vertical Scrolling | *boolean* | `false` | - |
|
||||||
| touchable | Whether touchable | *boolean* | `true` | - |
|
| touchable | Whether to allow swipe by touch gesture | *boolean* | `true` | - |
|
||||||
| show-indicators | Whether to show indicators | *boolean* | `true` | - |
|
| show-indicators | Whether to show indicators | *boolean* | `true` | - |
|
||||||
| indicator-color | Indicator color | *string* | `#1989fa` | - |
|
| indicator-color | Indicator color | *string* | `#1989fa` | - |
|
||||||
| initial-swipe | Index of initial swipe, start from 0 | *number* | `0` | - |
|
| initial-swipe | Index of initial swipe, start from 0 | *number* | `0` | - |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user