Repository navigation
feat: on back navigation, close mobile sidebar - #5462
Conversation
|
✔️ [V2] 🔨 Explore the source changes: 95d5b54 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6130d6da0f2baa000795bc30 😎 Browse the preview: https://deploy-preview-5462--docusaurus-2.netlify.app |
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5462--docusaurus-2.netlify.app/ |
|
Size Change: +532 B (0%) Total Size: 822 kB
ℹ️ View Unchanged
|
|
Very ambivalent feature. This is more of behavior expected from real mobile app, but we just have regular website in browser. And if user in browser presses on back button, it should go to previous page in browser history, because that's how browsers works. |
Yes but also PWA
Browsers can do what you tell them to do if std APIs allow that. Preventing navigation is a common pattern, most used when editing a form, but can be useful in other cases too.
It would work for any mobile (at least small width device) that has back/forward navigation, which is just more physically accessible on Android
I felt the pain of pressing the back button and leaving the page I was on, and also remember someone mentioned this issue a while ago (can't find ref). The weird thing is that it navigates backward, but the drawer remains open, so we only see the page transition happening through the overlay. If you use a full-screen drawer like the React-Native website, you don't really understand what is happening because your drawer remains open, and only the drawer highlighted items change. At least I think we should close the drawer when navigating back/forward (even if the navigation is not prevented).
Forgot to push yesterday, my new implementation is simpler. It doesn't feel like a huge JS/complexity addition even if the ROI is limited. In any case, I think we should close the drawer on POP events (even if we don't prevent the transition), so similar would need to be added. I think preventing the transition in this case is a nice UX addition. Note:
I'm going to move on and merge this because I think closing the drawer is what we should do, and what SPA doc competitors do too. If anyone ever complain about the prevented POP transition, we could easily remove this or make it optional (same code, it's just a matter of returning |
|
Well, I see, although I still remain of my opinion that such behavior inherent to mobile apps should not be implemented on regular website. Instead this, we could just fix mobile sidebar closing when pressing back button. Maybe get opinion from users (eg. on Twitter) about this before merging? |
|
Created a poll here: I'm going to just close the drawer for now and merge, and eventually block the navigation later if people agree with my proposition |
|
That's good option for now, thanks. |
* On back, close mobile navbar sidebar * more reliable code to block history pop events * android backbutton: just close the drawer without cancellin the backward navigation
* On back, close mobile navbar sidebar * more reliable code to block history pop events * android backbutton: just close the drawer without cancellin the backward navigation
Motivation
Android users are used to using the hardware back button of their phone to close menus and drawers (cf Android apps, like Gmail)
Docusaurus users on Android might try that, and instead of closing the opened sidebar drawer, it would navigate to the previous page, potentially leaving the Docusaurus site. We should try to fix that UX issue.
Unfortunately, there's no browser API to easily detect or prevent backward navigation, and we have to use some tricks on top of the
historypackage that offers ablock()feature.Still, it's not possible to distinguish easily between backward/forward navigation, so this remains a best effort.
Closing the mobile sidebar on forward navigation is not an UX issue + the probably of an user using forward navigation on mobile with the drawer open is low, so this is a safe usecase.
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
preview on browser + android