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

HTMLDialogElement.close() emits a close Event even when the dialog is already closed #1064

Closed
Schleuse opened this issue Sep 13, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Schleuse
Copy link
Contributor

Describe the bug
HTMLDialogElement.close() emits an close Event even when the dialog is already closed.
This behaviour differs from the implementation in Chrome or Firefox where calls to the close method on already closed dialogs don't trigger 'close' Events.

The Spec says:

The close(returnValue) method steps are:

If returnValue is not given, then set it to null.

Close the dialog this with returnValue.

When a dialog element subject is to be closed, with null or a string result, run these steps:

If subject does not have an open attribute, then return.

Remove subject's open attribute.

If the is modal flag of subject is true, then request an element to be removed from the top layer given subject.

Let wasModal be the value of subject's is modal flag.

Set the is modal flag of subject to false.

If result is not null, then set the returnValue attribute to result.

If subject's previously focused element is not null, then:

Let element be subject's previously focused element.

Set subject's previously focused element to null.

If subject's node document's focused area of the document's DOM anchor is a shadow-including inclusive descendant of element, or wasModal is true, then run the focusing steps for element; the viewport should not be scrolled by doing this step.

Queue an element task on the user interaction task source given the subject element to fire an event named close at subject.

The returnValue IDL attribute, on getting, must return the last value to which it was set. On setting, it must be set to the new value. When the element is created, it must be set to the empty string.

To Reproduce
Steps to reproduce the behavior:

  1. Create a closed Dialog-Element
  2. Register a event handler to the close event
  3. Call close() on the Dialog Element
  4. The Handler shouldn't be called, but it get's called

Expected behavior
The close-Event shouldn't be emitted when the dialog is already closed

@Schleuse Schleuse added the bug Something isn't working label Sep 13, 2023
@Schleuse Schleuse changed the title HTMLDialogElement.close() emits an close Event even when the dialog is already closed HTMLDialogElement.close() emits a close Event even when the dialog is already closed Sep 13, 2023
Schleuse pushed a commit to Schleuse/happy-dom that referenced this issue Sep 13, 2023
@Schleuse
Copy link
Contributor Author

I've created a simple example to examine the current browser behaviour:

https://codepen.io/Schleuse/pen/dywRvMZ

capricorn86 added a commit to Schleuse/happy-dom that referenced this issue Sep 14, 2023
…ose-emits-a-close-Event-even-when-the-dialog-is-already-closed
@capricorn86
Copy link
Owner

@Schleuse your fix has been released 🙂

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v11.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants