Closed pinkladywithcoco closed 6 years ago
Is the Top-Menu fixed? Maybe is your Trigger Button at the top and after closing the offcanvas its gets focused. Codpen or a test-site?
I have taken the code from: https://codepen.io/vmitsaras/pen/gwGwJE and updated it above so you can test youself. When we scroll down. Close the menu. Open again. It scrolls to top.
I have fixed the problem now
@pinkladywithcoco Do you mind sharing what you did to fix it? I'm running into the same issue.
Edit: nevermind @pinkladywithcoco I was able to fix it with the changes suggested by vmitsaras.
@daveromsey Do you have a Codepen?
Is the Top-Menu fixed? Maybe is your Trigger Button at the top and after closing the offcanvas its gets focused. Codpen or a test-site?
Hello @vmitsaras,
Thank you for chiming in!
Here's a Pen of the forked Demo that demonstrates the issues I'm experiencing, where upon opening, the offcanvas sidebar scrolls to the top and gives focus to an element. I'd prefer not to have the scrolling to the top or focus behavior.
In this fork, I duplicated a bunch of content within the Left Offcanvas panel to give it plenty of height and added some styles to .c-offcanvas
(bottom of the CSS panel) so that it would allow vertical scrolling and would highlight the focused element for clarity while troubleshooting.
To reproduce the issues, click on the Overlay Left button to open the Offcanvas menu, scroll down on the menu, close the menu. Now, open the menu again with the Overlay Left button. The menu will scroll to the top and focus the top item.
My use case is that I have a complex form inside the Offcanvas sidebar that users can toggle open and closed while working on it. Ideally, when they re-open the sidebar, the scroll position should remain where it was when they closed it.
You can control which element would be focused with the [data-focus]
.
Example for your Issue
<aside class="js-offcanvas" id="off-canvas-left" role="complementary">
<div class="c-offcanvas__inner o-box u-pos-relative" tabindex="-1" data-focus>
...
</div>
</aside>
@vmitsaras You're amazing! Thanks, that did the trick.
If you have many divs inside the menu when you scroll down. Close the menu with dataOffcanvas.close(); and open it again with dataOffcanvas.open(); then it scrolls to the top of menu. How can you make it stay there instead of scrolling to top??