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
  • Merge requests
  • !32438

collapse: prevent url change if `A` nested tag is clicked

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/joke2k/fix-collapse-nested-change-url into main Dec 11, 2020
  • Overview 2
  • Commits 6
  • Pipelines 0
  • Changes 2

Created by: joke2k

Removing jQuery the target of the click event is not the A tag if the user clicks on a nested tag, ignoring the preventDefault and changing the hash in the url.

What this PR does:

  • Add event.delegateTarget into the check for preventDefault
  • Test this behaviour

Details:

this code:

<a role="button" data-bs-toggle="collapse" class="collapsed" href="#collapse">
  <span id="nested">Clickme</span>
</a>
<div id="collapse" class="collapse"></div>

bubbles ups the default behaviour and changes the URL appending #collapse to it because the event.target is not an A tag, this let fail the check for event.preventDefault.

See on bs5:

https://github.com/twbs/bootstrap/blob/764e5298dea17e15bbcbf792204a45a761bedc0a/js/src/collapse.js#L372-L376

On bs4 jQuery did the work:

https://github.com/twbs/bootstrap/blob/a716fb03f965dc0846df479e14388b1b4b93d7ce/js/src/collapse.js#L361-L365

it happened with this commit https://github.com/twbs/bootstrap/commit/69e4d4f3ac897870e8186e22b19c5adf6043f3d4#diff-3cc7f0d8580d17c90274789ffc45552c56fed69ac7404d65e88ccccb81ffff31R378

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/joke2k/fix-collapse-nested-change-url