diff --git a/docs/markdown/v2-progress-tracking.md b/docs/markdown/v2-progress-tracking.md index bb0413b46..f0a73bdee 100644 --- a/docs/markdown/v2-progress-tracking.md +++ b/docs/markdown/v2-progress-tracking.md @@ -55,6 +55,7 @@ ### ActionSheet +- 新增`close-on-click-action`属性 - 支持同时使用`title`和`actions`属性 ### Button diff --git a/packages/action-sheet/en-US.md b/packages/action-sheet/en-US.md index 99a6e5323..bbfb87e21 100644 --- a/packages/action-sheet/en-US.md +++ b/packages/action-sheet/en-US.md @@ -95,6 +95,7 @@ export default { | title | Title | `String` | - | | cancel-text | Text of cancel button | `String` | - | | overlay | Whether to show overlay | `Boolean` | `true` | +| close-on-click-action | Whether to close when click action | `Boolean` | `false` | | close-on-click-overlay | Whether to close when click overlay | `Boolean` | `true` | | lazy-render | Whether to lazy render util appeared | `Boolean` | `true` | | get-container | Return the mount node for action-sheet | `String | () => HTMLElement` | - | diff --git a/packages/action-sheet/index.tsx b/packages/action-sheet/index.tsx index 156ecde3e..a525a7afb 100644 --- a/packages/action-sheet/index.tsx +++ b/packages/action-sheet/index.tsx @@ -23,6 +23,7 @@ export type ActionSheetProps = PopupMixinProps & { title?: string; actions: ActionSheetItem[]; cancelText?: string; + closeOnClickAction?: boolean; safeAreaInsetBottom?: boolean; }; @@ -52,6 +53,26 @@ function ActionSheet( } } + function onClickOption(item: ActionSheetItem, index: number) { + return function (event: Event) { + event.stopPropagation(); + + if (item.disabled || item.loading) { + return; + } + + if (item.callback) { + item.callback(item); + } + + emit(ctx, 'select', item, index); + + if (props.closeOnClickAction) { + emit(ctx, 'input', false); + } + }; + } + const Option = (item: ActionSheetItem, index: number) => (