Modal
Modal dialogs.
When To Use
When requiring users to interact with the application, but without jumping to a new page and interrupting the user's workflow, you can use Modal
to create a new floating layer over the current page to get user feedback or display information. Additionally, if you need show a simple confirmation dialog, you can use ModalService.Confirm()
, and so on.
Examples
Modal API#
Property | Description | Type | Default Value |
---|---|---|---|
AfterClose | ParameterSpecify a function that will be called when modal is closed | Func<Task> | -- |
BodyStyle | ParameterBody style for modal body element. Such as height, padding etc | String | -- |
CancelText | ParameterText or RenderFragment of the Cancel button, it will override the ModalLocale | OneOf<String, RenderFragment?? | -- |
Centered | Parametercentered | Boolean | -- |
Closable | ParameterWhether a close (x) button is visible on top right of the modal dialog or not | Boolean | true |
Draggable | ParameterWhether the modal dialog box be dragged | Boolean | -- |
DragInViewport | ParameterDrag and drop only within the Viewport | Boolean | true |
CloseIcon | Parametercloser icon RenderFragment, the default is a "X" | RenderFragment | close-outline |
ConfirmLoading | ParameterWhether to apply loading visual effect for OK button or not | Boolean | -- |
DestroyOnClose | ParameterWhether to unmount child components on onClose | Boolean | false |
Header | ParameterHeader content | RenderFragment | -- |
Footer | ParameterFooter content, set as Footer=null when you don't need default buttons | OneOf<String, RenderFragment?? | -- |
GetContainer | Parameterget or set the modal parent DOM, default is null: which is specifying document.body | ElementReference? | -- |
Keyboard | ParameterWhether support press esc to close | Boolean | true |
Mask | ParameterWhether show mask or not | Boolean | true |
MaskClosable | ParameterWhether to close the modal dialog when the mask (area outside the modal) is clicked | Boolean | true |
MaskStyle | ParameterStyle for modal's mask element | String | -- |
OkText | ParameterText of RenderFragment of the OK button, it will override the ModalLocale | OneOf<String, RenderFragment?? | null |
OkType | ParameterButton type of the OK button | String | ButtonType.Primary |
Title | ParameterThe modal dialog's title | String | -- |
TitleTemplate | ParameterThe modal dialog's title. Takes priority over Title. | RenderFragment | -- |
Visible | ParameterWhether the modal dialog is visible or not | Boolean | -- |
VisibleChanged | ParameterSpecify a function invoke when the modal dialog is visible or not | EventCallback<Boolean> | -- |
Width | ParameterWidth of the modal dialog, the default value is 520 | OneOf<String, Double> | 520 |
WrapClassName | ParameterThe class name of the container of the modal dialog | String | -- |
ZIndex | ParameterThe z-index of the Modal | Int32 | 1000 |
OnCancel | ParameterSpecify a function that will be called when a user clicks mask, close button on top right or Cancel button | EventCallback<MouseEventArgs> | -- |
OnOk | ParameterSpecify a function that will be called when a user clicks the OK button | EventCallback<MouseEventArgs> | -- |
OkButtonProps | ParameterThe OK button props | ButtonProps | -- |
CancelButtonProps | ParameterThe Cancel button props | ButtonProps | -- |
ChildContent | ParameterChild content | RenderFragment | -- |
Rtl | Is RTL | Boolean | -- |
Locale | ParameterModal Locale | ModalLocale | LocaleProvider.CurrentLocacle.Modal |
MaxBodyHeight | Parametermax modal content body height | String | -- |
Maximizable | Parametershow modal maximize button | Boolean | false |
MaximizeBtnIcon | ParameterThe icon of the maximize button when the modal is in normal state | RenderFragment | fullscreen-outline |
RestoreBtnIcon | ParameterThe icon of the maximize button when the modal is maximized | RenderFragment | fullscreen-exit-outline |
DefaultMaximized | ParameterMaximize the Modal during component initialization, and it will ignore the Maximizable value. | Boolean | false |
Resizable | ParameterResizable (Horizontal direction only) | Boolean | -- |
ForceRender | ParameterWhether to force to render the Modal dom before opening. | Boolean | -- |
Id | ParameterID for the component's HTML | String | Uniquely Generated ID |
Class | ParameterSpecifies one or more class names for an DOM element. | String | -- |
Style | ParameterSpecifies an inline style for a DOM element. | String | -- |
RefBack | ParameterA ForwardRef instance. You can get a reference to the internal DOM by using AntDesign.ForwardRef.Current . |
ForwardRef | -- |
ModalService API#
Method Signature | Return Type | Description |
---|---|---|
Confirm(ConfirmOptions props) | ConfirmRef | create and open a OK-Cancel Confirm dialog |
Info(ConfirmOptions options) | ConfirmRef | create and open a OK-Cancel Confirm dialog with info icon |
Success(ConfirmOptions options) | ConfirmRef | create and open a OK-Cancel Confirm dialog with success icon |
Error(ConfirmOptions options) | ConfirmRef | create and open a OK-Cancel Confirm dialog with error icon |
Warning(ConfirmOptions options) | ConfirmRef | create and open a OK-Cancel Confirm dialog with Warning icon |
ConfirmAsync(ConfirmOptions props) | Task<Boolean> | create and open a OK-Cancel Confirm dialog, and return a bool value which indicates whether the OK button has been clicked |
InfoAsync(ConfirmOptions options) | Task<Boolean> | create and open a OK-Cancel Confirm dialog with info icon, and return a bool value which indicates whether the OK button has been clicked |
SuccessAsync(ConfirmOptions options) | Task<Boolean> | create and open a OK-Cancel Confirm dialog with success icon, and return a bool value which indicates whether the OK button has been clicked |
ErrorAsync(ConfirmOptions options) | Task<Boolean> | create and open a OK-Cancel Confirm dialog with error icon, and return a bool value which indicates whether the OK button has been clicked |
WarningAsync(ConfirmOptions options) | Task<Boolean> | create and open a OK-Cancel Confirm dialog with warning icon, and return a bool value which indicates whether the OK button has been clicked |
Update(ConfirmRef confirmRef) | Task | update Confirm which Visible=true |
UpdateConfirmAsync(ConfirmRef confirmRef) | Task | update Confirm which Visible=true |
Destroy(ConfirmRef confirmRef) | Task | close a Confirm dialog |
DestroyConfirmAsync(ConfirmRef confirmRef) | Task | close the Confirm dialog |
DestroyAll() | Task | close all Confirm dialog |
DestroyAllConfirmAsync() | Task | close all Confirm dialog |
CreateAsync(ConfirmOptions config) | Task<ConfirmRef> | Create and open a OK-Cancel Confirm asynchronous |
CreateConfirmAsync(ConfirmOptions config) | Task<ConfirmRef> | Create and open a OK-Cancel Confirm asynchronous |
CreateAsync(ConfirmOptions config, TComponentOptions componentOptions) | Task<ConfirmRef<TResult>> | Create and open template Confirm dialog |
CreateConfirmAsync(ConfirmOptions config, TComponentOptions componentOptions) | Task<ConfirmRef<TResult>> | Create and open template Confirm dialog |
CreateModal(ModalOptions options) | ModalRef | Create and open a Modal |
CreateModal(ModalOptions options) | ModalRef<TResult> | Create and open a Modal |
CreateModal(ModalOptions options, TComponentOptions componentOptions) | ModalRef | Create and open a Modal with template |
CreateModal(ModalOptions options, TComponentOptions componentOptions) | ModalRef<TResult> | Create and open a Modal with template component |
CreateModalAsync(ModalOptions options) | Task<ModalRef> | Create and open a Modal |
CreateModalAsync(ModalOptions options) | Task<ModalRef<TResult>> | Create and open a Modal |
CreateModalAsync(ModalOptions options, TComponentOptions componentOptions) | Task<ModalRef> | Create and open a Modal with template |
CreateModalAsync(ModalOptions options, TComponentOptions componentOptions) | Task<ModalRef<TResult>> | Create and open a Modal with template |
ConfirmService API#
Method Signature | Return Type | Description |
---|---|---|
Show(OneOf<String, RenderFragment> content, OneOf<String, RenderFragment> title, ConfirmButtons confirmButtons, ConfirmIcon confirmIcon, ConfirmButtonOptions options, ConfirmAutoFocusButton? autoFocusButton) | Task<ConfirmResult> | show a confirm dialog like MessageBox of Windows |
Show(OneOf<String, RenderFragment> content, OneOf<String, RenderFragment> title, ConfirmButtons confirmButtons, ConfirmIcon confirmIcon) | Task<ConfirmResult> | show a confirm dialog like MessageBox of Windows |
ConfirmOptions API#
Property | Description | Type | Default Value |
---|---|---|---|
Locale | Confirm Locale | ConfirmLocale | -- |
ClassName | the class name of the element of ".ant-modal" | String | -- |
Visible | Boolean | -- | |
Content | ChildContent | OneOf<String, RenderFragment> | -- |
Icon | Confirm left top icon | RenderFragment | -- |
Style | .ant-modal element's style | String | -- |
AutoFocusButton | ConfirmAutoFocusButton | -- | |
OkType | set OK button type for the leftmost button: OK or Yes button | String | -- |
OkText | set OK button content for the leftmost button: OK or Yes button, it will override the ConfirmLocale | OneOf<String, RenderFragment?? | -- |
CancelText | set Cancel button content for the second on the left button: Cancel or NO button, it will override the ConfirmLocale | OneOf<String, RenderFragment?? | -- |
OnCancel | for OK-Cancel Confirm dialog, cancel button clicked callback. It's only trigger in Confirm created by ModalService mode | Func<ModalClosingEventArgs, Task> | -- |
OnOk | for OK-Cancel Confirm dialog, OK button clicked callback. It's only trigger in Confirm created by ModalService mode | Func<ModalClosingEventArgs, Task> | -- |
OkButtonProps | OK-Cancel Confirm dialog's OK button props. It is equivalent to Button1Props. | ButtonProps | -- |
CancelButtonProps | OK-Cancel Confirm dialog's cancel button props. It is equivalent to Button2Props. | ButtonProps | -- |
Button1Props | the leftmost button in LTR layout | ButtonProps | -- |
Button2Props | The second button on the left is in the LTR layout | ButtonProps | -- |
Button3Props | the rightmost button in LTR layout | ButtonProps | -- |
OkCancel | show Cancel button for OK-Cancel Confirm dialog | Boolean | -- |
PrefixCls | class name prefix | String | -- |
CancelText | modal default footer cancel text | OneOf<String, RenderFragment> | -- |
Centered | whether center display | Boolean | -- |
GetContainer | get or set the modal parent DOM | ElementReference? | -- |
Keyboard | Whether support press esc to close | Boolean | -- |
Mask | Whether show mask or not | Boolean | -- |
MaskClosable | Whether to close the modal dialog when the mask (area outside the modal) is clicked | Boolean | -- |
MaskStyle | Style for dialog's mask element | String | -- |
OkText | Text of the OK button | OneOf<String, RenderFragment> | -- |
Title | The modal dialog's title of String | String | -- |
TitleTemplate | The modal dialog's title of RenderFragment | RenderFragment | -- |
Width | Width of the modal dialog | OneOf<String, Double> | -- |
ZIndex | The z-index of the Modal | Int32 | -- |
Rtl | Is RTL | Boolean | -- |
FAQs
Why does the custom component inherited from FeedbackComponent<>
not execute the Dispose
method when a Modal created by ModalService.CreateModalAsync<>
is closed?
Modal will not be removed from DOM by default after closing, so the Dispose
method of custom component will not be executed. You can change this default behavior by setting modalOptions.DestroyOnClose=true
.