-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
collapse: prevent url change if A
nested tag is clicked
#32438
Conversation
We need tests for this, can you add a test please? |
emm... tests were already in the PR 😅 |
Oops, sorry I missed them! |
@@ -374,6 +374,29 @@ describe('Collapse', () => { | |||
}) | |||
|
|||
describe('data-api', () => { | |||
it('should prevent url change if click on nested elements', done => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this describe
is the right place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a bug of the data-api as you can see from the part of collapse.js file:
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
// preventDefault only for <a> elements (which change the URL) not inside the collapsible element
if (event.target.tagName === 'A' || (event.delegateTarget && event.delegateTarget.tagName === 'A')) {
event.preventDefault()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is It right?
A
nested tag is clicked
Co-authored-by: XhmikosR <[email protected]>
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:
event.delegateTarget
into the check for preventDefaultDetails:
this code:
bubbles ups the default behaviour and changes the URL appending #collapse to it because the
event.target
is not anA
tag, this let fail the check forevent.preventDefault
.See on bs5:
bootstrap/js/src/collapse.js
Lines 372 to 376 in 764e529
On bs4 jQuery did the work:
bootstrap/js/src/collapse.js
Lines 361 to 365 in a716fb0
it happened with this commit 69e4d4f#diff-3cc7f0d8580d17c90274789ffc45552c56fed69ac7404d65e88ccccb81ffff31R378