Skip to content
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 mobile sidebar scrolling issue #1787

Merged

Conversation

arnellebalane
Copy link
Contributor

@arnellebalane arnellebalane commented Feb 12, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

When the sidebar is opened in mobile layout, the darkened background (.sidebar-bg) is longer than the actual sidebar element itself, making it possible to scroll past the bottom of the actual sidebar.

The cause of the issue is the height: 1000%; declaration set in the .sidebar-bg element. This PR refactors the sidebar behavior to not rely on the .sidebar-bg element as the darkened background. The darkened background is moved to the .side-bar element as box-shadow, and the .sidebar-bg elements are removed, ensuring that scrolling will not go past the bottom of the sidebar. ensures that the sidebar wrapper and .sidebar-bg elements are sized correctly, and that the sidebar does not overflow the wrapper. With the sidebar always within the wrapper, the darkened background will not scroll as well.

Related Tickets & Documents

#1746

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

UI stays the same after the changes are applied.

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Feb 12, 2019
@CLAassistant
Copy link

CLAassistant commented Feb 12, 2019

CLA assistant check
All committers have signed the CLA.

@Link2Twenty
Copy link
Contributor

Link2Twenty commented Feb 12, 2019

I don't think it needs to be quite so drastic, I think these changes should fix the issue.

.home .sidebar-wrapper {
  height: calc(100vh - 48px);
}

.home .sidebar-wrapper .sidebar-bg {
  /* remove height: 1000%; */
}

.home .sidebar-wrapper.swiped-in .side-bar { 
  height: calc(100% - 2px);
  overflow-y: auto;
  /* remove min-height: calc(100vh - 44px); */
  /* remove top: 0; */
  /* remove bottom: 0; */
}

All can be found here

https://github.com/thepracticaldev/dev.to/blob/9e4d9ecac16a70cbe64c351506cecf3de5e12459/app/assets/stylesheets/articles.scss#L688-L726

@arnellebalane
Copy link
Contributor Author

@Link2Twenty Apologies for the drastic changes to fix the issue 🙏 I've reverted my changes and applied your suggestion, which is much more simpler than what I originally did 😄

@Link2Twenty
Copy link
Contributor

@arnellebalane No need to apologise. Your solution worked too after all 🙂.

The CSS solution does have a side effect in which the position of the sidebar is remembered when it is closed and opened again. So we might want to add something to JS to scroll back up on close, though I'm not sure that's crucial.

@Link2Twenty
Copy link
Contributor

This is the code the controls the opening and closing of the sidebars

https://github.com/thepracticaldev/dev.to/blob/65110550d8c2231f73ff99ae305a46b7b0bcb4f9/app/assets/javascripts/utilities/slideSidebar.js#L1-L18

Adding this line should make the side-bar scroll back up on close, provided that's the expected behavour.

function slideSidebar(side,direction){ 
   if (!document.getElementById("sidebar-wrapper-"+side)){ 
     return; 
   } 
   if (direction === "intoView") { 
     document.getElementById("articles-list").classList.add("modal-open"); 
     document.getElementsByTagName("body")[0].classList.add("modal-open"); 
     document.getElementById("sidebar-wrapper-"+side).classList.add("swiped-in") 
     document.getElementById("sidebar-wrapper-"+side).scrollTop=0 
     document.getElementById("articles-list").addEventListener("touchmove", preventDefaultAction, false); 
   } 
   else { 
     document.getElementById("articles-list").classList.remove("modal-open"); 
     document.getElementsByTagName("body")[0].classList.remove("modal-open"); 
     document.getElementById("sidebar-wrapper-"+side).classList.remove("swiped-in"); 
     // New line!
     document.getElementById("sidebar-wrapper-"+side).querySelector('.side-bar').scroll(0,0); 
     document.getElementById("articles-list").removeEventListener("touchmove", preventDefaultAction, false); 
   } 
 }

@arnellebalane
Copy link
Contributor Author

arnellebalane commented Feb 13, 2019

@Link2Twenty I will also try to add scrolling back the sidebar to the top on close in this PR, that sounds like the behavior that I would expect from the sidebar as well.

@Zhao-Andy
Copy link
Contributor

Hey @arnellebalane, sounds like you're still working on this so I'm going to add WIP to the title. Feel free to change it and leave a comment when it's ready for review again.

@Zhao-Andy Zhao-Andy changed the title Fix mobile sidebar scrolling issue WIP Fix mobile sidebar scrolling issue Feb 15, 2019
@pr-triage pr-triage bot removed the PR: unreviewed bot applied label for PR's with no review label Feb 15, 2019
@Zhao-Andy Zhao-Andy changed the title WIP Fix mobile sidebar scrolling issue [WIP] Fix mobile sidebar scrolling issue Feb 15, 2019
@arnellebalane
Copy link
Contributor Author

@Zhao-Andy Yes I'm still working on this. Thank you! 👍

@arnellebalane arnellebalane force-pushed the refactor/mobile-sidebar-background branch from 4ea2340 to 33ca1df Compare February 19, 2019 14:44
@arnellebalane arnellebalane force-pushed the refactor/mobile-sidebar-background branch from 1adf9e9 to 5450081 Compare February 19, 2019 14:49
@arnellebalane
Copy link
Contributor Author

@Link2Twenty I have updated this PR to make the sidebar scroll back to top when they are closed. The diff for the JS file that I changed will show a lot of changes because ESLint automatically fixed most of the linting issues on that file upon committing my changes 😄

@arnellebalane arnellebalane changed the title [WIP] Fix mobile sidebar scrolling issue Fix mobile sidebar scrolling issue Feb 19, 2019
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Feb 19, 2019
Copy link
Contributor

@Zhao-Andy Zhao-Andy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Tested on Android Firefox and Chrome, and iOS Safari.

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Feb 20, 2019
@maestromac maestromac merged commit e642080 into forem:master Feb 21, 2019
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Feb 21, 2019
@arnellebalane arnellebalane deleted the refactor/mobile-sidebar-background branch February 26, 2019 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants