fix(dialog): fixed escape key bug when persistent and improved destroy logic #823
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
Describe the new behavior?
This PR contains a fix for a bug in Chrome where where pressing the escape key twice in succession would always close the native
<dialog>
because you can't prevent default on thecancel
event multiple times... This is seen as a bug by the community but Chrome has said that it is not. The workaround is to just use akeydown
listener on the window and prevent default when the escape key is pressed, and this works across all browsers but is unfortunate.The second fix included with this PR is the teardown logic for when a dialog is removed from the DOM before the close animation is complete (by setting
open
tofalse
). This was causing some cleanup logic to not run. We now will always run the proper cleanup logic from thedisconnectedCallback()
regardless of the animation state, and this ensures that any resources are released and state is reset properly.