Is there a way to tell if a modal is displayed?

Is there a way to tell if a modal is displayed?

I’m using the following to add it:

myform.showModal()

But later I want to check if it is visible.

I’ve given an updated answer below, this, while not wrong, isn’t an ideal answer. I’m not a fan of deleting answers (as you can always learn from things, even if they’re not ideal), but please see my other answer :slightly_smiling_face:


Old answer

I don’t think there is any way to check this “on” the <dialog> element, but it shouldn’t be too difficult setting a sort of flag to check this, something along the lines of

let modalIsVisible = false;

function myFunction() {
  [...]
  modalIsVisible = true;
  myform.showModal().finally(() => {
    modalIsVisible = false;
  }
}

function anotherFn() {
  if (modalIsVisible) {
    [...]
  }
}
1 Like

Forget what I’ve said, there seems to be a myform.open readonly boolean doing this: https://adobexdplatform.com/plugin-docs/reference/uxp/class/HTMLDialogElement.html#htmldialogelementopen--boolean :wink:

2 Likes

Does this also work for panels? I’m getting back false for panelDialog.open when the panel is visible.

Is panelDialog a modal dialog box (<dialog> element), or is it part of your modeless panel’s UI content? Is it’s the modeless panel, then you should be able to do something similar to Pablo’s first answer, using the panel show() and hide() callbacks.

1 Like