-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
[FIX] website: make anchor links work in offcanvas mobile menu #146132
Conversation
Alternative mentioned in commit message would be about just this line if the Offcanvas.getInstance(offcanvasEl).hide(); |
3d99df3
to
63cfea3
Compare
f59769f
to
423cf77
Compare
@qsm-odoo opw PR ready, feel free to delegate it should you prefer |
423cf77
to
5413854
Compare
I'll retarget to 16, here is the diff needed where offcanvas was introduced (probably 17) diff --git a/addons/web/tooling/_eslintrc.json b/addons/web/tooling/_eslintrc.json
index 467b2ff2ab785..016030f9cf324 100644
--- a/addons/web/tooling/_eslintrc.json
+++ b/addons/web/tooling/_eslintrc.json
@@ -43,24 +43,26 @@
"_": "readonly",
"Chart": "readonly",
"fuzzy": "readonly",
- "Popover": "readonly",
"StackTrace": "readonly",
"QUnit": "readonly",
"luxon": "readonly",
"py": "readonly",
"FullCalendar": "readonly",
"globalThis": "readonly",
- "Modal": "readonly",
- "Dropdown": "readonly",
"ScrollSpy": "readonly",
- "Tooltip": "readonly",
- "Collapse": "readonly",
- "Alert": "readonly",
"module": "readonly",
"chai": "readonly",
"describe": "readonly",
"it": "readonly",
"mocha": "readonly",
- "DOMPurify": "readonly"
+ "DOMPurify": "readonly",
+
+ "Alert": "readonly",
+ "Collapse": "readonly",
+ "Dropdown": "readonly",
+ "Modal": "readonly",
+ "Offcanvas": "readonly",
+ "Popover": "readonly",
+ "Tooltip": "readonly"
}
}
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index d1203c79de4ac..c4541e0d2bddd 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -1039,8 +1039,23 @@ registry.anchorSlide = publicWidget.Widget.extend({
if (!$anchor.length || !scrollValue) {
return;
}
- ev.preventDefault();
- this._scrollTo($anchor, scrollValue);
+
+ const offcanvasEl = document.querySelector('.offcanvas.o_navbar_mobile');
+ if (offcanvasEl && offcanvasEl.classList.contains('show')) {
+ // Special case for anchors in offcanvas in mobile: we can't just
+ // _scrollTo() after preventDefault because preventDefault would
+ // prevent the offcanvas to be closed. The choice is then to close
+ // it ourselves manually and once it's fully closed, then start our
+ // own smooth scrolling.
+ ev.preventDefault();
+ Offcanvas.getInstance(offcanvasEl).hide();
+ offcanvasEl.addEventListener('hidden.bs.offcanvas', () => {
+ this._scrollTo($anchor, scrollValue);
+ });
+ } else {
+ ev.preventDefault();
+ this._scrollTo($anchor, scrollValue);
+ }
},
}); Commit msg
|
5413854
to
8ef0cb0
Compare
@qsm-odoo this is ready, retargeted 16.0 as discussed here: #146132 (comment) |
8ef0cb0
to
d511d91
Compare
A anchor menu in the mobile collapse related to an element in the current page doesn't work correctly: - The collapse-menu doesn't close - If the menu is large enough, on mobile, you actually don't even see the page scrolling behind it so it looks like the click did nothing. This is probably because of the switch from BS4 to BS5. In later version, it's even worse, as we are using bootstrap Offcanvas instead of collapse, creating another bug: - The page doesn't scroll at all This will be fixed in the forward port. This commit simply manually closes the collapse before starting our own smooth scrolling. It also targets the desktop offcanvas menu (when hamburger layout is selected). opw-3604963
d511d91
to
9633a7e
Compare
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.
- Made this change
- Fixed a small typo in commit message "worst" instead of "worse"
@robodoo r+
A anchor menu in the mobile collapse related to an element in the current page doesn't work correctly: - The collapse-menu doesn't close - If the menu is large enough, on mobile, you actually don't even see the page scrolling behind it so it looks like the click did nothing. This is probably because of the switch from BS4 to BS5. In later version, it's even worse, as we are using bootstrap Offcanvas instead of collapse, creating another bug: - The page doesn't scroll at all This will be fixed in the forward port. This commit simply manually closes the collapse before starting our own smooth scrolling. It also targets the desktop offcanvas menu (when hamburger layout is selected). opw-3604963 closes #146132 Signed-off-by: Quentin Smetz (qsm) <[email protected]>
3 similar comments
A anchor menu in the mobile collapse related to an element in the current page doesn't work correctly: - The collapse-menu doesn't close - If the menu is large enough, on mobile, you actually don't even see the page scrolling behind it so it looks like the click did nothing. This is probably because of the switch from BS4 to BS5. In later version, it's even worse, as we are using bootstrap Offcanvas instead of collapse, creating another bug: - The page doesn't scroll at all This will be fixed in the forward port. This commit simply manually closes the collapse before starting our own smooth scrolling. It also targets the desktop offcanvas menu (when hamburger layout is selected). opw-3604963 closes odoo#146132 Signed-off-by: Quentin Smetz (qsm) <[email protected]>
A anchor menu in the mobile offcanvas related to an element in the
current page doesn't work in offcanvas.
This is because the menu anchor navigation is hooked to use our own
scrolling behavior instead of the browser one.
Doing so, we preventDefault, which prevent the offcanvas menu to close
itself when clicking on a anchor menu.
This commit simply manually close the offcanvas and once the closing
animation is complete, starts our own smooth scrolling.
Another possibility would have been to just close manually the offcanvas
without a preventDefault and without a call to our custom scrolling
method.
Doing so, the browser would naturally scroll to the element while we
close the offcanvas but it would be less elegant as you wouldn't see the
scrolling animation.
Note that the offcanvas was introduced with commit 1.
opw-3604963