google-apps-scriptdialogmodal-dialog

showModalDialog vs showModelessDialog


The documentation on showModalDialog vs showModelessDialog says this:

In almost all cases, a modal dialog or sidebar is a better choice than a modeless dialog.

https://developers.google.com/apps-script/reference/base/ui#showModalDialog(Object,String)

Why is it a better choice?

This is a sub-question from my overall aim is of creating a Google Apps Script function to download a zip file directly to my local device.

This answer to a related question provides two solutions. The first from Tanaike uses showModalDialog and the second from TheMaster uses showModelessDialog.

My question arises from a desire to understand their answers better.


Solution

  • Just the previous line of the documentation that is quoted, says the difference:

    Modal dialogs prevent the user from interacting with anything other than the dialog. By contrast, modeless dialogs and sidebars let the user interact with the editor

    The recommendation to use modal rather than modeless, assumes the UI focus should be on the dialog rather than the editor. For example, If the dialog asks a question, the user should answer it first rather than ignoring it and using the underlying editor(say Google sheets).

    On the other hand, if you're using the dialog to play a song or an video, while you also want to work with the underlying Google sheets, a modeless dialog is required. Notably, this scenario is rare. That's why a modal dialog is preferred in most cases.