Skip to content

Modal: fix dispose function#38857

Closed
louismaximepiton wants to merge 2 commits into
mainfrom
main-lmp-modal-dispose-fix
Closed

Modal: fix dispose function#38857
louismaximepiton wants to merge 2 commits into
mainfrom
main-lmp-modal-dispose-fix

Conversation

@louismaximepiton

@louismaximepiton louismaximepiton commented Jul 3, 2023

Copy link
Copy Markdown
Member

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
Comment thread js/src/modal.js Outdated
dispose() {
EventHandler.off(window, EVENT_KEY)
EventHandler.off(this._dialog, EVENT_KEY)
this._element.addEventListener(EVENT_HIDDEN, () => {

Copy link
Copy Markdown
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

Comment thread js/src/modal.js

@GeoSot GeoSot Jul 6, 2023

Copy link
Copy Markdown
Member

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

@mdo

mdo commented Jun 26, 2026

Copy link
Copy Markdown
Member

v6-dev's Dialog/Drawer dispose() now closes the element and clears the body scroll-lock when disposed while open (#35934, in #42544), covering the body-attribute cleanup here. Closing in favor of the v6 work since this targets v5 and isn't slated for a v5.x release. Thanks!

@mdo mdo closed this Jun 26, 2026
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

4 participants