mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Stepper): add long-press prop
This commit is contained in:
parent
b8a6b67975
commit
2f3ec6a3d4
@ -116,6 +116,7 @@ export default {
|
|||||||
| button-size `v2.0.5` | Button size | *string \| number* | `28px` |
|
| button-size `v2.0.5` | Button size | *string \| number* | `28px` |
|
||||||
| show-plus `v2.1.2` | Whether to show plus button | *boolean* | `true` |
|
| show-plus `v2.1.2` | Whether to show plus button | *boolean* | `true` |
|
||||||
| show-minus `v2.1.2` | Whether to show minus button | *boolean* | `true` |
|
| show-minus `v2.1.2` | Whether to show minus button | *boolean* | `true` |
|
||||||
|
| long-press `v2.4.3` | Whether to allow long press | *boolean* | `true` |
|
||||||
| decimal-length `v2.2.1` | Decimal length | *number* | - |
|
| decimal-length `v2.2.1` | Decimal length | *number* | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
@ -138,6 +138,7 @@ export default {
|
|||||||
| button-size `v2.0.5` | 按钮大小以及输入框高度,默认单位为`px` | *string \| number* | `28px` |
|
| button-size `v2.0.5` | 按钮大小以及输入框高度,默认单位为`px` | *string \| number* | `28px` |
|
||||||
| show-plus `v2.1.2` | 是否显示增加按钮 | *boolean* | `true` |
|
| show-plus `v2.1.2` | 是否显示增加按钮 | *boolean* | `true` |
|
||||||
| show-minus `v2.1.2` | 是否显示减少按钮 | *boolean* | `true` |
|
| show-minus `v2.1.2` | 是否显示减少按钮 | *boolean* | `true` |
|
||||||
|
| long-press `v2.4.3` | 是否开启长按手势 | *boolean* | `true` |
|
||||||
| decimal-length `v2.2.1` | 固定显示的小数位数 | *number* | - |
|
| decimal-length `v2.2.1` | 固定显示的小数位数 | *number* | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
@ -56,6 +56,10 @@ export default createComponent({
|
|||||||
showMinus: {
|
showMinus: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
|
},
|
||||||
|
longPress: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -222,12 +226,16 @@ export default createComponent({
|
|||||||
|
|
||||||
longPressStep() {
|
longPressStep() {
|
||||||
this.longPressTimer = setTimeout(() => {
|
this.longPressTimer = setTimeout(() => {
|
||||||
this.onChange(this.type);
|
this.onChange();
|
||||||
this.longPressStep(this.type);
|
this.longPressStep(this.type);
|
||||||
}, LONG_PRESS_INTERVAL);
|
}, LONG_PRESS_INTERVAL);
|
||||||
},
|
},
|
||||||
|
|
||||||
onTouchStart() {
|
onTouchStart() {
|
||||||
|
if (!this.longPress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(this.longPressTimer);
|
clearTimeout(this.longPressTimer);
|
||||||
this.isLongPress = false;
|
this.isLongPress = false;
|
||||||
|
|
||||||
@ -239,6 +247,10 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onTouchEnd(event) {
|
onTouchEnd(event) {
|
||||||
|
if (!this.longPress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearTimeout(this.longPressTimer);
|
clearTimeout(this.longPressTimer);
|
||||||
|
|
||||||
if (this.isLongPress) {
|
if (this.isLongPress) {
|
||||||
@ -256,7 +268,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
touchstart: () => {
|
touchstart: () => {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.onTouchStart(type);
|
this.onTouchStart();
|
||||||
},
|
},
|
||||||
touchend: this.onTouchEnd,
|
touchend: this.onTouchEnd,
|
||||||
touchcancel: this.onTouchEnd
|
touchcancel: this.onTouchEnd
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`button-size prop 1`] = `<div class="van-stepper"><button type="button" class="van-stepper__minus van-stepper__minus--disabled" style="width: 2rem; height: 2rem;"></button><input type="number" role="spinbutton" aria-valuemax="Infinity" aria-valuemin="1" aria-valuenow="1" class="van-stepper__input" style="height: 2rem;"><button type="button" class="van-stepper__plus" style="width: 2rem; height: 2rem;"></button></div>`;
|
||||||
|
|
||||||
exports[`disable stepper input 1`] = `<div class="van-stepper"><button type="button" class="van-stepper__minus van-stepper__minus--disabled"></button><input type="number" role="spinbutton" aria-valuemax="Infinity" aria-valuemin="1" aria-valuenow="1" disabled="disabled" class="van-stepper__input"><button type="button" class="van-stepper__plus"></button></div>`;
|
exports[`disable stepper input 1`] = `<div class="van-stepper"><button type="button" class="van-stepper__minus van-stepper__minus--disabled"></button><input type="number" role="spinbutton" aria-valuemax="Infinity" aria-valuemin="1" aria-valuenow="1" disabled="disabled" class="van-stepper__input"><button type="button" class="van-stepper__plus"></button></div>`;
|
||||||
|
|
||||||
exports[`disabled stepper 1`] = `<div class="van-stepper"><button type="button" class="van-stepper__minus van-stepper__minus--disabled"></button><input type="number" role="spinbutton" aria-valuemax="Infinity" aria-valuemin="1" aria-valuenow="1" disabled="disabled" class="van-stepper__input"><button type="button" class="van-stepper__plus van-stepper__plus--disabled"></button></div>`;
|
exports[`disabled stepper 1`] = `<div class="van-stepper"><button type="button" class="van-stepper__minus van-stepper__minus--disabled"></button><input type="number" role="spinbutton" aria-valuemax="Infinity" aria-valuemin="1" aria-valuenow="1" disabled="disabled" class="van-stepper__input"><button type="button" class="van-stepper__plus van-stepper__plus--disabled"></button></div>`;
|
||||||
|
@ -89,6 +89,22 @@ test('long press', async () => {
|
|||||||
expect(wrapper.emitted('input')).toEqual([[2], [3], [4]]);
|
expect(wrapper.emitted('input')).toEqual([[2], [3], [4]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('disable long press', async () => {
|
||||||
|
const wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
value: 1,
|
||||||
|
longPress: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const plus = wrapper.find('.van-stepper__plus');
|
||||||
|
plus.trigger('touchstart');
|
||||||
|
await later(800);
|
||||||
|
plus.trigger('touchend');
|
||||||
|
|
||||||
|
expect(wrapper.emitted('input')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
test('filter value during user input', () => {
|
test('filter value during user input', () => {
|
||||||
const wrapper = mount(Stepper, {
|
const wrapper = mount(Stepper, {
|
||||||
propsData: {
|
propsData: {
|
||||||
@ -178,6 +194,15 @@ test('input-width prop', () => {
|
|||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('button-size prop', () => {
|
||||||
|
const wrapper = mount(Stepper, {
|
||||||
|
propsData: {
|
||||||
|
buttonSize: '2rem'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
test('async-change prop', () => {
|
test('async-change prop', () => {
|
||||||
const wrapper = mount(Stepper, {
|
const wrapper = mount(Stepper, {
|
||||||
propsData: {
|
propsData: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user