Skip to content

Open a plugin modal

Use api.ui.openModal() when trusted plugin code needs a workflow that cannot be represented by a structured campaign. The configurator owns dialog behavior; the plugin renders the modal body.

Open from an outlet action

ts
api.ui.mount('page-header:actions', (container) => {
  const button = document.createElement('button')
  button.type = 'button'
  button.textContent = 'Get help'

  let closeModal: (() => void) | undefined

  const openHelp = () => {
    closeModal?.()
    closeModal = api.ui.openModal({
      id: 'customer-shopping-help',
      title: 'Shopping help',
      description: 'Choose how you want to start.',
      size: 'medium',
      closeLabel: 'Close shopping help',
      render(modalContainer, context) {
        const chooseVehicle = document.createElement('button')
        chooseVehicle.type = 'button'
        chooseVehicle.textContent = 'Choose my vehicle'

        const startSearch = () => {
          api.commands.openSearchByVehicle()
          context.close('api')
        }

        chooseVehicle.addEventListener('click', startSearch)
        modalContainer.appendChild(chooseVehicle)

        return () => {
          chooseVehicle.removeEventListener('click', startSearch)
          chooseVehicle.remove()
        }
      },
    })
  }

  button.addEventListener('click', openHelp)
  container.appendChild(button)

  return () => {
    closeModal?.()
    button.removeEventListener('click', openHelp)
    button.remove()
  }
})
FieldPurpose
idStable identifier used by diagnostics and events.
titleVisible dialog title.
descriptionOptional supporting text.
sizesmall, medium, large, or fullscreen.
closeLabelAccessible label for the close control.
closeOnBackdropWhether a backdrop click closes the modal.
closeOnEscapeWhether Escape closes the modal.
renderCallback that renders the body and optionally returns cleanup.

Only one plugin modal is active at a time. Opening another replaces the current plugin modal.

Use marketing campaigns for event-triggered promotional prompts with structured creative and frequency rules.

Icon Visualizer developer documentation