ant-design-blazor/components/modal/confirmDialog/Confirm.razor
zxyao 8301230bda fix(module: modal): auto focus the ok button and remove the focus of the trigger button (#1838)
* fix: second opening of focus in modal fails if DestroyOnClose is false

* fix: confirm cannot get focus element

* fix: set ConfirmAutoFocusButton is OK

* fix: module ImagePreview cannot close on second click

* fix: blur active element when comfirm focus element is disabled
2021-08-28 15:28:50 +00:00

186 lines
7.4 KiB
C#

@namespace AntDesign
@inherits AntDomComponentBase
@using OneOf;
<DialogWrapper Visible="@Config.Visible"
DestroyOnClose="true"
Config="@_dialogOptions"
Style="@Config.Style"
>
<div class="ant-modal-confirm-body-wrapper">
<div class="ant-modal-confirm-body">
@if (Config.Icon != null)
{
@(Config.Icon)
}
@if (Config.TitleTemplate != null)
{
<span class="ant-modal-confirm-title">
@Config.TitleTemplate
</span>
}
else if (!string.IsNullOrWhiteSpace(Config.Title))
{
<span class="ant-modal-confirm-title">
@Config.Title
</span>
}
<div class="ant-modal-confirm-content">
@if (Config.Content.IsT0)
{
@(Config.Content.AsT0)
}
else
{
@(Config.Content.AsT1)
}
</div>
</div>
<div class="ant-modal-confirm-btns">
@{
RenderFragment BuildButton(ButtonProps props,
Func<MouseEventArgs, Task> onClick, string id = null)
{
if (props == null) return null;
id ??= "ant-blazor-" + Guid.NewGuid();
var onClickEvent = new EventCallback<MouseEventArgs>(this, onClick);
Button innerBtnRef = null;
var children = props.ChildContent!.Value;
RenderFragment compontent = (@<Button @ref="@innerBtnRef"
OnClick="@onClickEvent"
Block="@props.Block"
Ghost="@props.Ghost"
Loading="@props.Loading"
Type="@props.Type"
Shape="@props.Shape"
Size="@props.Size"
Icon="@props.Icon"
Disabled="@props.Disabled"
Danger="@props.IsDanger"
Id="@id"
>
@{
if (children.IsT0)
{
@(children.AsT0)
}
else
{
@(children.AsT1)
}
}
</Button>);
return compontent;
}
}
@switch (Config.ConfirmButtons)
{
case ConfirmButtons.OK:
{
@BuildButton(Config.Button1Props, async (e) =>
{
await HandleBtn1Click(e, ConfirmResult.OK);
}, _okBtnId)
;
break;
}
case ConfirmButtons.OKCancel:
{
@BuildButton(Config.Button1Props, async (e) =>
{
await HandleBtn1Click(e, ConfirmResult.OK);
}, _okBtnId)
;
@BuildButton(Config.Button2Props, async (e) =>
{
await HandleBtn2Click(e, ConfirmResult.Cancel);
}, _cancelBtnId)
;
break;
}
case ConfirmButtons.YesNo:
{
@BuildButton(Config.Button1Props, async (e) =>
{
await HandleBtn1Click(e, ConfirmResult.Yes);
}, _okBtnId)
;
@BuildButton(Config.Button2Props, async (e) =>
{
await HandleBtn2Click(e, ConfirmResult.No);
}, _cancelBtnId)
;
break;
}
case ConfirmButtons.YesNoCancel:
{
@BuildButton(Config.Button1Props, async (e) =>
{
await HandleBtn1Click(e, ConfirmResult.Yes);
}, _okBtnId)
;
@BuildButton(Config.Button2Props, async (e) =>
{
await HandleBtn2Click(e, ConfirmResult.No);
}, _cancelBtnId)
;
@BuildButton(Config.Button3Props, async (e) =>
{
await HandleBtn3Click(e, ConfirmResult.Cancel);
})
;
break;
}
case ConfirmButtons.RetryCancel:
{
@BuildButton(Config.Button1Props, async (e) =>
{
await HandleBtn1Click(e, ConfirmResult.Retry);
}, _okBtnId)
;
@BuildButton(Config.Button2Props, async (e) =>
{
await HandleBtn2Click(e, ConfirmResult.Cancel);
}, _cancelBtnId)
;
break;
}
case ConfirmButtons.AbortRetryIgnore:
{
@BuildButton(Config.Button1Props, async (e) =>
{
await HandleBtn1Click(e, ConfirmResult.Abort);
}, _okBtnId)
;
@BuildButton(Config.Button2Props, async (e) =>
{
await HandleBtn2Click(e, ConfirmResult.Retry);
}, _cancelBtnId)
;
@BuildButton(Config.Button3Props, async (e) =>
{
await HandleBtn3Click(e, ConfirmResult.Ignore);
})
;
break;
}
}
</div>
</div>
</DialogWrapper>