Class Modal

java.lang.Object
io.mindspice.simplypages.core.HtmlTag
io.mindspice.simplypages.components.display.Modal
All Implemented Interfaces:
Component

public class Modal extends HtmlTag
Backdrop-based modal renderer with configurable close behavior.

Mutable and not thread-safe. Configure and render within a request-scoped lifecycle. For reuse, stop mutating shared instances and render stable structures with per-request context data.

Load the framework JavaScript for focus entry/containment, close actions and focus restoration on direct or HTMX insertion. The container is a named modal dialog; untitled dialogs use Dialog as their accessible name without adding a visible header.

Security boundary: withModalId(String) validates generated identifiers. Body/footer components are rendered with the supplied context.

  • Method Details

    • create

      public static Modal create()
      Creates a new modal instance.
      Returns:
      new modal
    • withModalId

      public Modal withModalId(String modalId)
      Sets backdrop id and the prefix used for the dialog title id.
      Parameters:
      modalId - id matching ^[a-zA-Z][a-zA-Z0-9_-]*$
      Returns:
      this modal
      Throws:
      IllegalArgumentException - when id format is invalid
    • withTitle

      public Modal withTitle(String title)
      Sets modal title text.
      Parameters:
      title - title text
      Returns:
      this modal
    • withBody

      public Modal withBody(Component body)
      Sets modal body component.
      Parameters:
      body - body component
      Returns:
      this modal
    • withFooter

      public Modal withFooter(Component footer)
      Sets modal footer component.
      Parameters:
      footer - footer component
      Returns:
      this modal
    • closeOnBackdrop

      public Modal closeOnBackdrop(boolean enabled)
      Toggles close-on-backdrop behavior.
      Parameters:
      enabled - true to enable backdrop click to close
      Returns:
      this modal
    • closeOnEscape

      public Modal closeOnEscape(boolean enabled)
      Toggles close-on-escape behavior.
      Parameters:
      enabled - true to enable ESC key to close
      Returns:
      this modal
    • showCloseButton

      public Modal showCloseButton(boolean show)
      Toggles close button rendering in modal header.
      Parameters:
      show - true to show close button
      Returns:
      this modal
    • render

      public String render(RenderContext context)
      Renders complete modal/backdrop markup with configured behavior metadata and content.
      Specified by:
      render in interface Component
      Overrides:
      render in class HtmlTag
      Parameters:
      context - context used for slot resolution and render policy
      Returns:
      modal HTML
    • render

      public String render()
      Ensures modal markup rendering is identical for context-aware parent render paths.
      Returns:
      modal HTML