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

Modal: fix dispose function #38857

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

louismaximepiton
Copy link
Member

@louismaximepiton louismaximepiton commented Jul 3, 2023

Description

Call a function that removes all body attributes before disposing the modal itself.

However, I'm not quite sure about my comprehension of our doc explanation about the dispose function. Shall it remove the modal element from the DOM or shall it just remove the modal object instance ? both ?

Motivation & Context

Fix the dispose call when a modal is shown.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • (NA) My change introduces changes to the documentation
  • (NA) I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Live previews

Related issues

Closes #35934.

@louismaximepiton louismaximepiton requested a review from a team as a code owner July 3, 2023 09:35
js/src/modal.js Outdated
@@ -139,13 +139,17 @@ class Modal extends BaseComponent {
}

dispose() {
EventHandler.off(window, EVENT_KEY)
EventHandler.off(this._dialog, EVENT_KEY)
this._element.addEventListener(EVENT_HIDDEN, () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this._element.addEventListener(EVENT_HIDDEN, () => {
EventHandler.on(this._element, EVENT_HIDDEN, () => {

try this syntax to be aligned with the rest codebase ;wink

Copy link
Member

@GeoSot GeoSot Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to add a test too, supporting your solution

NOTE for reviewers:
The proposed change is valid.
My only consideration is, whether we should handle such situations or not. In case we decide to handle them, we should also think about the other components too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

modal.dispose() does not fully clean up body element mutations
3 participants