I’m utilizing React-Bootstrap Offcanvas as a mobile sidebar to scroll to various portions of the page, however when I click the links on my iPhone they do not work, with some exceptions, and seems to focus on elements behind it. On desktop, when I inspect and change the dimensions everything works fine.
Using onClick event listener to trigger scrollIntoView method via document.getElementById(id).scrollIntoView();
Using chrome browser on both devices. Website is hosted through Github Pages. Website is a personal site I’m using to practice my code and share things I enjoy.
The code is a little large and is linked here: https://github.com/ShaunDM/ShaunDM.github.io
Website here: https://shaundm.github.io/#/
Relevant components:
- src/layout/Layout.js for the offcanvas.
- src/layout/Navbar.js for looking into whether components behind the offcanvas are being affected, specifically the navbar.
- src/sidebar (primarily ./SidebarList.js) for the offcanvas content.
- src/layout/Hit.js and it’s relevant variables/functions in src/layout/Layout.js if you’d like to track events on a mobile device.
Exception 1:
If I activate the Offcanvas and zoom out through pinching, the links work. This doesn’t work if I zoom in. Will often maintain functionality for a few seconds after initial zoom out without having to repeat method.
Exception 1 in action, can see highlight of elements behind click
Exception 2:
On one of my pages I have a sidebar that contains multiple lists of links. It’ll navigate the horizontal scroll, but not the document’s y axis, unless you use exception 1. Page: https://shaundm.github.io/#/portfolio
Exception 2 in action
I’ve implemented a component that will render either “Hit” or “No hit” that I use to track triggers of events on a mobile device. When I click the link it registers as being fired. When I use it to track onFocus, onFocusCapture, onTouchStart, and/or onTouchStartCapture of the elements behind the Offcanvas it doesn’t register despite the elements being highlighted afterward as if they are being focused.
Can see trigger of link click event here. The trigger of events regarding elements behind offcanvas are in the prior gifs. Also can see zoom in not working.
Be aware that not all of the pages render a sidebar, Home and Contact Me. There will be no triple bar icon on the navbar.
The current version of the code has set up to change based on if a link is clicked or not.
- I’ve tried implementing z-index:9999 for the sidebar, and 0 for , #root, and the container I surround all my code with except the offcanvas.
- Setting the sidebar’s position to relative instead of fixed and set relative to the above mentioned elements, while maintaining z-index above.
- I’ve moved the offcanvas sidebar as a direct child of .
- I’ve double checked on my desktop browser that the sidebar is not being overlapped, by the elements behind using inspect and it doesn’t seem to be the case.
- I’ve tried eliminating custom css for the offcanvas.
- I’ve tried surrounding the
document.getElementById(id).scrollIntoView();
method with setTimeOut, which seemed to fix others with similar issues. - I’ve tried utilizing
e.preventDefault()
prior to triggering scrollIntoView().