Dialog

new Dialog(options) → {Class}

A dialog component to house modals, dialogs or prompts.

Parameters:
NameTypeDescription
optionsobject

The options for the dialog.

Properties
NameTypeDescription
alertButtonTextstring

The text for the alert button.

cancelButtonTextstring

The text for the cancel button.

closeButtonClassesstring

The classes for the close button. Space seperated string.

closeButtonTitlestring

The title for the close button.

confirmButtonAttributesstring

The attributes for the confirm button. Space seperated string.

confirmButtonIconstring

The icon for the confirm button.

confirmButtonTextstring

The text for the confirm button.

contentstring

The content for the dialog. HTML allowed.

idstring

The id for the dialog.

lockBodyboolean

Whether to lock the body behind the dialog

maskBlurboolean

Whether to blur the background when the dialog is open.

maskClassesstring

The classes for the mask. Space seperated string.

maskThemeboolean

Background mask theme, none, light or dark.

modestring

The mode for the dialog. alert, confirm or dialog.

onClosefunction

Function to fire when closed

onConfirmfunction

Function to fire when confirm button is clicked in dialog mode

onOpenfunction

Function to fire when opened

positionstring

The position for the dialog. center, top or bottom.

renderOnInitboolean

Render on initialization?

targetstring

Append target for the dialog and its mask. Uses querySelectorAll

titlestring

The title for the dialog.

titleIconstring

The icon for the title.

titleIconColorstring

The color for the title icon.

triggersstring

The optional selector[s] of the trigger that shows it

wrapperClassesstring

The classes for the wrapper. Space seperated string.

zIndexnumber

The z-index for the dialog.

Since
  • 1.0.6
Returns:

The class instance.

Type: 
Class
Example
import Dialog from '@gravityforms/components/html/admin/modules/Dialog';

function Example() {
     const dialogInstance = new Dialog( {
         id: 'example-dialog',
         renderOnInit: false,
         target: '#example-target',
         targetPosition: 'beforeend',
     } );

     // Some time later we can render it. This is only done if we set renderOnInit to false.
     // If true it will render on initialization.
     dialogInstance.init();
}

Members

(static) closeDialog

Closes the dialog and fires the onClose function that can be passed in. Can be used by external developers by firing the method on the instance. Also closes all instances if the event 'gform/dialog/close-all' is fired on the document.

Since
  • 1.0.6

(static) handleConfirm

Handles a confirm button click and closes if the option is true.

Since
  • 1.0.6

(static) handleKeyEvents

Handles accessibility focus looping on the dialog using the focusLoop util.

Since
  • 1.0.6

(static) handleMaskClick

Handles closing the dialog on mask click.

Since
  • 1.0.6

(static) handleTriggerClick

Handles opening/closing the dialog on a trigger click.

Since
  • 1.0.6

(static) maybeCloseDialog

Closes all instances except the one that gets passed the activeId when the event 'gform/dialog/close' is fired on the document.

Since
  • 1.0.6

Methods

(static) bindEvents() → {void}

Binds the events for this component.

Since
  • 1.0.6
Returns:
Type: 
void

(static) dialogTemplate(options)

The template function that returns html for the dialog. Options below are passed from constructor and described there.

Parameters:
NameTypeDescription
optionsobject

The options for the dialog.

Properties
NameTypeDescription
alertButtonTextstring

The text for the alert button.

cancelButtonTextstring

The text for the cancel button.

closeButtonClassesstring

The classes for the close button. Space seperated string.

closeButtonAriaLabelstring

The aria label for the close button.

closeButtonSizestring

The size for the close button.

closeButtonTitlestring

The title for the close button.

closeButtonTypestring

The type for the close button.

confirmButtonAttributesstring

The attributes for the confirm button. Space seperated string.

confirmButtonIconstring

The icon for the confirm button.

confirmButtonTextstring

The text for the confirm button.

contentstring

The content for the dialog. HTML allowed.

idstring

The id for the dialog.

maskBlurboolean

Whether to blur the background when the dialog is open.

maskClassesstring

The classes for the mask. Space seperated string.

maskThemeboolean

Background mask theme, none, light or dark.

modestring

The mode for the dialog. alert, confirm or dialog.

positionstring

The position for the dialog. center, top or bottom.

titlestring

The title for the dialog.

titleIconstring

The icon for the title.

titleIconColorstring

The color for the title icon.

wrapperClassesstring

The classes for the wrapper. Space seperated string.

zIndexnumber

The z-index for the dialog.

Since
  • 1.0.6
Returns:

string

Example
import { dialogTemplate } from '@gravityforms/components/html/admin/modules/Dialog';

function Example() {
     const dialogHTML = dialogTemplate( options );
     document.body.insertAdjacentHTML( 'beforeend', dialogHTML );
}

(static) init() → {void}

Initialize the component.

Since
  • 1.1.16
Returns:
Type: 
void

(static) render() → {void}

Renders the component into the dom.

Since
  • 1.0.6
Returns:
Type: 
void

(static) showDialog() → {void}

Opens the dialog and fires the onOpen function that can be passed in.

Since
  • 1.0.6
Returns:
Type: 
void

(static) storeElements() → {void}

Stores useful HTMLElements on the instance in the elements namespace after render

Since
  • 1.0.6
Returns:
Type: 
void