Skip to main content

Modal

Properties

PropertyTypeDescription
titlestringTitle of the modal
openbooleanControls whether the modal is displayed
cancelButtonPropstableSee cancelButtonProps
cancelTextstringText of the cancel button
centeredbooleanWhether the modal should be centered
closeIconboolean/stringIcon shown in top-right to close modal
confirmLoadingbooleanLoading visual effect for OK button or not
keyboardbooleanWhether the user can use the keyboard
maskbooleanWhether to show mask
okButtonPropstableSee okButtonProps
okTextstringText of the OK button
okTypestringButton type of the OK button
autoFocusButtonnil, ok, cancelWhat item to be focused when modal is shown
onOkfunction(event)Fired when "ok" is pressed
onCancelfunction(event)Fired when "cancel" is pressed
afterClosefunction()Fired whenever modal is closed
afterOpenChangefunction(open)Fired whenever modal is opened

Children

Modal does support children.

Example

local modal; modal = AM:createElement("Modal", {
title = "Modal Title",
open = true,
onOk = function(_, _, event)
-- Run when ok button is pressed
print("onOk: ", json.encode(event, {indent = true}))
print("Pressed Ok")
modal.open = false
end,
onCancel = function(_, _, event)
-- Run when cancel or X button is pressed
print("onCancel: ", json.encode(event, {indent = true}))
print("Pressed Cancel")
modal.open = false
end,
afterClose = function(_, _)
-- Run when modal is closed from any source
print("afterClose")
end,
afterOpenChange = function(_, _, open)
-- Run when modal is opened or closed
print("afterOpenChange: ", open)
end,
}, {
AM:createElement("Text", {text = "Child Text"}),
})

image

title

Title of modal.

open

Weather the modal is shown, set this to show/hide it.

myUI:createElement("Button", {
text = "Open Modal",
onClick = function(_, _, event)
local newState = not modal.open
if newState then
button.text = "Close Modal"
else
button.text = "Open Modal"
end
modal.open = newState
end,
})

cancelButtonProps

Properties for the cancel button.

Properties can be found Here (Button)

Or here ant design button props

cancelText

Text on the cancel button.

centered

Weather the modal popup is centered to the users screen.

closeIcon

Icon of the close button in the top-right of the modal.

confirmLoading

"Whether to apply loading visual effect for OK button or not"

keyboard

Weather user can use keyboard in the modal.

So if user presses "ESCAPE" the cancel function will be fired.

mask

Weather to draw a mask behind the modal popup.

A mask is like a "overlay" making the background darker (by default).

okButtonProps

Properties for the ok button.

Properties can be found Here (Button)

Or here ant design button props

okText

Text displayed on the ok button.

okType

Button type of the ok button.

Can also be set with okButtonProps

Types can be found Here (Button)

autoFocusButton (not working, deprecated?)

What button (if any) should be focused when modal is shown.

autoFocusButton = "nil" will not focus either button. This is the default.

autoFocusButton = "ok" will focus the ok button.

autoFocusButton = "cancel" will focus the cancel button.