From f509117d0295b9590e84811f348cf99dd26ab9f4 Mon Sep 17 00:00:00 2001 From: zxyao Date: Wed, 9 Sep 2020 11:33:41 +0800 Subject: [PATCH] fix(module: drawer): merge oncancel and onclose (#522) (#547) * fix(module: drawer): merge oncancel and onclose (#522) * docs: update drawer docs * fix: drawer service cannot catch onclose on 'x' clicked Co-authored-by: James Yeung --- components/drawer/DrawerContainer.razor.cs | 2 -- components/drawer/DrawerRef.cs | 16 +++++++--------- components/drawer/DrawerService.cs | 1 - components/drawer/config/DrawerOptions.cs | 6 ------ .../Components/Drawer/demo/Drawer_service.razor | 2 +- .../Demos/Components/Drawer/doc/index.en-US.md | 3 +-- .../Demos/Components/Drawer/doc/index.zh-CN.md | 1 - 7 files changed, 9 insertions(+), 22 deletions(-) diff --git a/components/drawer/DrawerContainer.razor.cs b/components/drawer/DrawerContainer.razor.cs index eaf48991..68f1170d 100644 --- a/components/drawer/DrawerContainer.razor.cs +++ b/components/drawer/DrawerContainer.razor.cs @@ -53,7 +53,5 @@ namespace AntDesign _drawerRefs.Remove(drawerRef); } } - - } } diff --git a/components/drawer/DrawerRef.cs b/components/drawer/DrawerRef.cs index cd1adf6b..68facc19 100644 --- a/components/drawer/DrawerRef.cs +++ b/components/drawer/DrawerRef.cs @@ -24,7 +24,6 @@ namespace AntDesign await _service.CloseAsync(this); await OnClose.Invoke(result); } - } public class DrawerRef @@ -36,7 +35,7 @@ namespace AntDesign public Func OnOpen { get; set; } - public Func OnClose { get; set; } + public Func OnClose { get; set; } internal DrawerRef(DrawerOptions config) { @@ -50,7 +49,7 @@ namespace AntDesign } /// - /// 打开抽屉 + /// open a drawer /// /// public async Task OpenAsync() @@ -61,25 +60,24 @@ namespace AntDesign } /// - /// 关闭抽屉无返回值 + /// close the drawer without return value /// /// public async Task CloseAsync() { await _service.CloseAsync(this); if (OnClose != null) - await OnClose.Invoke(); + await OnClose.Invoke(new DrawerClosingEventArgs(false)); } - internal async Task HandleOnCancel() { var args = new DrawerClosingEventArgs(false); - if (Config.OnCancel != null) + if (OnClose != null) { - await Config.OnCancel.Invoke(args); + await OnClose.Invoke(args); } - if (args.Cancel == false) + if (!args.Cancel) await _service.CloseAsync(this); } } diff --git a/components/drawer/DrawerService.cs b/components/drawer/DrawerService.cs index 67b49d54..acd14e02 100644 --- a/components/drawer/DrawerService.cs +++ b/components/drawer/DrawerService.cs @@ -62,7 +62,6 @@ namespace AntDesign return Task.CompletedTask; } - internal Task CloseAsync(DrawerRef drawerRef) { if (OnCloseEvent != null) diff --git a/components/drawer/config/DrawerOptions.cs b/components/drawer/config/DrawerOptions.cs index 72ec967d..abac98d5 100644 --- a/components/drawer/config/DrawerOptions.cs +++ b/components/drawer/config/DrawerOptions.cs @@ -48,11 +48,5 @@ namespace AntDesign public int OffsetY { get; set; } = 0; public bool Visible { get; set; } - - /// - /// 点击关闭时触发,返回false时,取消关闭动作 - /// - public Func OnCancel { get; set; } - } } diff --git a/site/AntBlazor.Docs/Demos/Components/Drawer/demo/Drawer_service.razor b/site/AntBlazor.Docs/Demos/Components/Drawer/demo/Drawer_service.razor index 9347dfd8..80e3dca4 100644 --- a/site/AntBlazor.Docs/Demos/Components/Drawer/demo/Drawer_service.razor +++ b/site/AntBlazor.Docs/Demos/Components/Drawer/demo/Drawer_service.razor @@ -24,7 +24,7 @@ _drawerRef = await DrawerService.CreateAsync(options); - _drawerRef.OnClose = () => + _drawerRef.OnClose = (args) => { Console.WriteLine("Close Drawer"); return Task.CompletedTask; diff --git a/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.en-US.md b/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.en-US.md index 0a3ddfda..a2ed9e11 100644 --- a/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.en-US.md +++ b/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.en-US.md @@ -50,13 +50,12 @@ Drawer comes very handy. | CreateAsync | create and open an Drawer | `DrawerConfig` | `DrawerRef` | | CreateAsync | create and open an Drawer | `DrawerConfig` , TContentParams | `DrawerRef` | -### DrawerConfig +### DrawerOptions | | ˵ | | Ĭֵ | | ------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | --------- | | Content | The drawer body content. | `OneOf` | - | | ContentParams | The component inputs the param / The Template context. | `D` | - | -| OnCancel | Execute when click on the mask or the upper cancel button (return false to prevent closing) | - | | Closable | Whether a close (x) button is visible on top right of the Drawer dialog or not. | `boolean` | `true` | | MaskClosable | Clicking on the mask (area outside the Drawer) to close the Drawer or not. | `boolean` | `true` | | Mask | Whether to show mask or not. | `boolean` | `true` | diff --git a/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.zh-CN.md b/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.zh-CN.md index 6dc16893..3e97a6cc 100644 --- a/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.zh-CN.md +++ b/site/AntBlazor.Docs/Demos/Components/Drawer/doc/index.zh-CN.md @@ -52,7 +52,6 @@ cover: https://gw.alipayobjects.com/zos/alicdn/7z8NJQhFb/Drawer.svg | ------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | --------- | | Content | Drawer body 的内容 | `OneOf` | - | | ContentParams | 内容组件的输入参数 / Template的 context | `D` | - | -| OnCancel | 点击遮罩层或右上角叉时执行,将自动关闭对话框(返回false可阻止关闭) | `() => Promise` `Func` | - | | Closable | 是否显示右上角的关闭按钮 | `boolean` | `true` | | MaskClosable | 点击蒙层是否允许关闭 | `boolean` | `true` | | Mask | 是否展示遮罩 | `boolean` | `true` |