code: function findNearestDialog(el) {
      while (el) {
        if (el.localName === 'dialog') {
          return /** @type {HTMLDialogElement} */ (el);
        }
        el = el.parentElement;
      }
      return null;
    }
docs: Finds the nearest <dialog> from the passed element.
  
  @param {Element} el to search from
  @return {HTMLDialogElement} dialog found