Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Issues
  • #37613
Closed
Open
Issue created Dec 08, 2022 by Administrator@rootContributor2 of 2 checklist items completed2/2 checklist items

Allow hiding modal synchronously after removing fade class

Created by: joakimriedel

Prerequisites

  • I have searched for duplicate or closed feature requests
  • I have read the contributing guidelines

Proposal

When using Bootstrap modals with a reactive framework such as Vue, there might be some rare issues when a component get unmounted from DOM without the possibility to wait for the hide transition to complete if fade class is active. In these cases, I have code in place to remove the fade class to force a synchronous hide without transition.

          console.warn("perf: modal was still visible during sync disposal");

          // https://github.com/twbs/bootstrap/issues/35934
          // disable fade if we're about to unmount while still showing modal
          // otherwise hide call will be asynchronous
          if (modalElement.classList.contains("fade")) {
            modalElement.classList.remove("fade");

            // hack: patch backdrop since it stores its animated value on created
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            (modal.value as any)._backdrop._config.isAnimated = false;
          }

          // the hide call below should now be guaranteed to be synchronous

Currently the isAnimated prop is set during construction of Backdrop instance.

    return new Backdrop({
      isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value,
      isAnimated: this._isAnimated()
    })

(https://github.com/twbs/bootstrap/blob/main/js/src/modal.js#L159)

My suggestion is to make isAnimated property a function instead of boolean.

    return new Backdrop({
      isVisible: Boolean(this._config.backdrop), // 'static' option will be translated to true, and booleans will keep their value,
      isAnimated: () => this._isAnimated()
    })

This way, if fade class is removed, the backdrop will synchronously remove itself instead of using transition (which will fail since element is removed from DOM when transition ends).

Motivation and context

This feature request is to make the backdrop to properly reflect the fact that the fade class has been removed from modal.

It relates somewhat to https://github.com/twbs/bootstrap/issues/35934 since the issue is that the backdrop is not cleaned up on dispose, only on hide.

I know I am supposed to wait for transitions but there are some rare instances where this cannot be 100% guaranteed and I would like my code to be resilient for this.

I'd be happy to submit a PR if this is something you want to implement.

Assignee
Assign to
Time tracking