mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] Button: add touchstart event (#3039)
This commit is contained in:
parent
2a4c2d86e9
commit
5a44d204bd
@ -88,4 +88,5 @@ Vue.use(Button);
|
|||||||
|
|
||||||
| Event | Description | Arguments |
|
| Event | Description | Arguments |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| click | Triggered when click button and not disabled or loading | - |
|
| click | Triggered when click button and not disabled or loading | event: Event |
|
||||||
|
| touchstart | Triggered when touch start | event: TouchEvent |
|
||||||
|
@ -46,28 +46,35 @@ function Button(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onTouchstart = (event: TouchEvent) => {
|
||||||
|
emit(ctx, 'touchstart', event);
|
||||||
|
};
|
||||||
|
|
||||||
|
const classes = [
|
||||||
|
bem([
|
||||||
|
type,
|
||||||
|
props.size,
|
||||||
|
{
|
||||||
|
loading,
|
||||||
|
disabled,
|
||||||
|
hairline,
|
||||||
|
block: props.block,
|
||||||
|
plain: props.plain,
|
||||||
|
round: props.round,
|
||||||
|
square: props.square,
|
||||||
|
'bottom-action': props.bottomAction
|
||||||
|
}
|
||||||
|
]),
|
||||||
|
{ 'van-hairline--surround': hairline }
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tag
|
<tag
|
||||||
|
class={classes}
|
||||||
type={props.nativeType}
|
type={props.nativeType}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
class={[
|
|
||||||
bem([
|
|
||||||
type,
|
|
||||||
props.size,
|
|
||||||
{
|
|
||||||
loading,
|
|
||||||
disabled,
|
|
||||||
hairline,
|
|
||||||
block: props.block,
|
|
||||||
plain: props.plain,
|
|
||||||
round: props.round,
|
|
||||||
square: props.square,
|
|
||||||
'bottom-action': props.bottomAction
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
{ 'van-hairline--surround': hairline }
|
|
||||||
]}
|
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
onTouchstart={onTouchstart}
|
||||||
{...inherit(ctx)}
|
{...inherit(ctx)}
|
||||||
>
|
>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
@ -58,3 +58,17 @@ test('not trigger click event when loading', () => {
|
|||||||
wrapper.trigger('click');
|
wrapper.trigger('click');
|
||||||
expect(onClick).toHaveBeenCalledTimes(0);
|
expect(onClick).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('touchstart event', () => {
|
||||||
|
const onTouchstart = jest.fn();
|
||||||
|
const wrapper = mount(Button, {
|
||||||
|
context: {
|
||||||
|
on: {
|
||||||
|
touchstart: onTouchstart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.trigger('touchstart');
|
||||||
|
expect(onTouchstart).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
@ -99,4 +99,5 @@ Vue.use(Button);
|
|||||||
|
|
||||||
| 事件名 | 说明 | 参数 |
|
| 事件名 | 说明 | 参数 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| click | 点击按钮且按钮状态不为加载或禁用时触发 | - |
|
| click | 点击按钮,且按钮状态不为加载或禁用时触发 | event: Event |
|
||||||
|
| touchstart | 原生 touchstart 事件 | event: TouchEvent |
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<demo-section>
|
<demo-section>
|
||||||
<demo-block :title="$t('default')">
|
<demo-block :title="$t('default')">
|
||||||
<van-button @touchstart.native.stop="keyboard = 'default'">
|
<van-button @touchstart.stop="keyboard = 'default'">
|
||||||
{{ $t('button1') }}
|
{{ $t('button1') }}
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
@ -16,7 +16,7 @@
|
|||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block :title="$t('custom')">
|
<demo-block :title="$t('custom')">
|
||||||
<van-button @touchstart.native.stop="keyboard = 'custom'">
|
<van-button @touchstart.stop="keyboard = 'custom'">
|
||||||
{{ $t('button2') }}
|
{{ $t('button2') }}
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ Vue.use(NumberKeyboard);
|
|||||||
#### Default Style
|
#### Default Style
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-button @touchstart.native.stop="show = true">
|
<van-button @touchstart.stop="show = true">
|
||||||
Show Keyboard
|
Show Keyboard
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ Vue.use(NumberKeyboard);
|
|||||||
#### 默认样式
|
#### 默认样式
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-button @touchstart.native.stop="show = true">
|
<van-button @touchstart.stop="show = true">
|
||||||
弹出默认键盘
|
弹出默认键盘
|
||||||
</van-button>
|
</van-button>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user