Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close and cancel events for dialog and snackbar #1583

Closed
bennypowers opened this issue Jul 26, 2020 · 2 comments · Fixed by #4463
Closed

close and cancel events for dialog and snackbar #1583

bennypowers opened this issue Jul 26, 2020 · 2 comments · Fixed by #4463
Assignees
Labels
Type: Feature New feature or request

Comments

@bennypowers
Copy link

bennypowers commented Jul 26, 2020

Is your feature request related to a problem? Please describe.
Consider the case of a <pwa-update> element, which defines a UI for the popular "click to update" pattern in PWAs

<pwa-update>
  <dialog slot="notifyer">
    <form method="dialog">
      <p>App Updated</p>
      <button type="submit" value="reload">OK</button>
      <button type="submit" value="cancel">Cancel</button>
    </form>
  </dialog>
</pwa-update>

The authors of <pwa-update> would like to give users flexibility to put any dialog implementation in the notifyer slot, including <mwc-dialog> and <mwc-snackbar>

By adopting the standard interface of <dialog>, in addition to the custom APIs already present, users could more easily use the material components as drop-in replacements.

HTMLDialogElement fires close and cancel events depending on how it was interacted with. Dialog and Snackbar, however, fire closing and closed events. By implementing the close and cancel events as well, Dialog and Snackbar could function as drop-in replacements for HTMLDialogElement.

Describe the solution you'd like
Dialog and Snackbar should implement close and cancel events in addition to the existing closing and closed events. It's open to discussion when in the lifecycle close and cancel should fire. An initial intuition suggests after non-default-prevented closing and before closed.

Describe alternatives you've considered
Our aforementioned <pwa-update> authors would likely expose a JavaScript API to their element as an escape hatch, and for gluing in non-standard custom-elements, however, we'd prefer a "just works" composable solution using standard, class-agnostic interfaces.

Users could also write their own wrappers

<pwa-update>
  <wraps-mwc-dialog-as-dialog slot="notifyer">
    <mwc-dialog>
      <form method="dialog">
        <p>App Updated</p>
        <button type="submit" value="reload">OK</button>
        <button type="submit" value="cancel">Cancel</button>
      </form>
    </mwc-dialog>
  </wraps-mwc-dialog-as-dialog>
</pwa-update>

But that seems to my mind a bit of a reach

Additional context
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement

@YonatanKra
Copy link
Contributor

Hi @dfreedm and @e111077 .
I've created a PR for this for thedialog (#1697). Could you please check it?
I have no issue creating a PR for the same issue for thesnackbar or adding the snackbar to this PR.
It's probably be the same technique.

copybara-service bot pushed a commit that referenced this issue Jun 26, 2023
fixes #1583

PiperOrigin-RevId: 543535752
copybara-service bot pushed a commit that referenced this issue Jun 26, 2023
fixes #1583

PiperOrigin-RevId: 543535752
copybara-service bot pushed a commit that referenced this issue Jun 27, 2023
fixes #1583

PiperOrigin-RevId: 543535752
copybara-service bot pushed a commit that referenced this issue Jun 27, 2023
fixes #1583

PiperOrigin-RevId: 543535752
@e111077
Copy link
Contributor

e111077 commented Jun 27, 2023

forwent close in favor of closing + closed, and don't know how it will interact with the dialog interaction model. Though re-dispatched the cancel event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
3 participants