diff --git a/packages/vant/src/swipe-cell/README.md b/packages/vant/src/swipe-cell/README.md index 49b99f0e0..fd405b4fe 100644 --- a/packages/vant/src/swipe-cell/README.md +++ b/packages/vant/src/swipe-cell/README.md @@ -112,6 +112,7 @@ export default { | name | Identifier of SwipeCell, usually a unique string or number | _number \| string_ | - | | left-width | Width of the left swipe area | _number \| string_ | `auto` | | right-width | Width of the right swipe area | _number \| string_ | `auto` | +| threshold | Swipe threshold (ratio of swipe distance to side width) | _number \| string_ | `0.15` | | before-close | Callback function before close | _(args) => boolean \| Promise\_ | - | | disabled | Whether to disabled swipe | _boolean_ | `false` | | stop-propagation | Whether to stop touchmove event propagation | _boolean_ | `false` | diff --git a/packages/vant/src/swipe-cell/README.zh-CN.md b/packages/vant/src/swipe-cell/README.zh-CN.md index 20756ee7d..1ebb09a6b 100644 --- a/packages/vant/src/swipe-cell/README.zh-CN.md +++ b/packages/vant/src/swipe-cell/README.zh-CN.md @@ -119,6 +119,7 @@ export default { | name | 标识符,通常为一个唯一的字符串或数字,可以在事件参数中获取到 | _number \| string_ | `''` | | left-width | 指定左侧滑动区域宽度,单位为 `px` | _number \| string_ | `auto` | | right-width | 指定右侧滑动区域宽度,单位为 `px` | _number \| string_ | `auto` | +| threshold | 滑动触发阈值(滑动距离与滑动区域宽度的比例) | _number \| string_ | `0.15` | | before-close | 关闭前的回调函数,返回 `false` 可阻止关闭,支持返回 Promise | _(args) => boolean \| Promise\_ | - | | disabled | 是否禁用滑动 | _boolean_ | `false` | | stop-propagation | 是否阻止滑动事件冒泡 | _boolean_ | `false` | diff --git a/packages/vant/src/swipe-cell/SwipeCell.tsx b/packages/vant/src/swipe-cell/SwipeCell.tsx index d3eed4f4f..61312e532 100644 --- a/packages/vant/src/swipe-cell/SwipeCell.tsx +++ b/packages/vant/src/swipe-cell/SwipeCell.tsx @@ -39,6 +39,11 @@ export const swipeCellProps = { disabled: Boolean, leftWidth: numericProp, rightWidth: numericProp, + threshold: { + type: numericProp, + default: 0.15, + validator: (value: number | string) => +value >= 0 && +value <= 1, + }, beforeClose: Function as PropType, stopPropagation: Boolean, }; @@ -106,8 +111,8 @@ export default defineComponent({ const toggle = (side: SwipeCellSide) => { const offset = Math.abs(state.offset); - const THRESHOLD = 0.15; - const threshold = opened ? 1 - THRESHOLD : THRESHOLD; + const thresholdValue = +props.threshold; + const threshold = opened ? 1 - thresholdValue : thresholdValue; const width = side === 'left' ? leftWidth.value : rightWidth.value; if (width && offset > width * threshold) {