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 hamburger menu scrolling #15000

Merged
merged 2 commits into from Oct 19, 2021

Conversation

takmar
Copy link
Contributor

@takmar takmar commented Oct 10, 2021

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

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

When navigating to the Forem hamburger menu and then scrolling down, you cannot scroll back up. The menu gets stuck and instead when you try to scroll up it scrolls the page underneath the menu.

The reason for the problem mentioned above is that the body element is enabled to scroll when the hamburger menu is opened. So I added overflow: hidden to body[data-left-nav-state='open'] selector so that it prevents scroll the body while opening the menu.

data-left-nav-state='open' is set when the hamburger menu is opened. The code is below.

function toggleBurgerMenu() {
const { leftNavState = 'closed' } = document.body.dataset;
document.body.dataset.leftNavState =
leftNavState === 'open' ? 'closed' : 'open';
}

Related Tickets & Documents

Closes #14757

QA Instructions, Screenshots, Recordings

  1. Open the hamburger menu
  2. Scroll the menu

Oct-10-2021 13-11-27

UI accessibility concerns?

Added/updated tests?

  • Yes
  • No, and this is why: I don't know how to write the test for scrolling, and also if it is needed.
  • I need help with writing tests

[Forem core team only] How will this change be communicated?

[optional] Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

McdYk9

@takmar takmar requested review from a team, nickytonline and Ridhwana and removed request for a team October 10, 2021 04:23
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 10, 2021
@github-actions
Copy link
Contributor

Thank you for opening this PR! We appreciate you!

For all pull requests coming from third-party forks we will need to
review the PR before we can process it through our CI pipelines.

A Forem Team member will review this contribution and get back to
you as soon as possible!

@rhymes rhymes requested a review from djuber October 11, 2021 08:33
@ludwiczakpawel
Copy link
Contributor

Hey, there's still something off with pulling down - it does trigger the refresher in the background.

Nagranie.z.ekranu.2021-10-11.o.18.56.18.mov

if (typeof window.PullToRefresh !== 'undefined') {
document.body.dataset.leftNavState === 'open'
? window.PullToRefresh.destroyAll()
: window.PullToRefresh.init();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This prevents executing pull to refresh, but I'm not sure this is the correct way to handle PullToRefresh.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just repeating the code here for my own understanding, when calling toggleBurgerMenu (expanding the left nav menu), this will remove all setup PullToRefresh handlers via the public destroyAll function, and if we're toggling to closed, we set it back up.

I noticed the place we call init() originally, in base.js, we pass an option object

{
          mainElement: 'body',
          passive: true,
          onRefresh: function(){
            window.location.reload();
            }
         }

Do you think we should do that here as well? I'm not familiar with the code but the public api you're calling for init expects an object o and sets undefined to an empty object.

I assume these options should be reset when you call init() here. Or the existing options somehow accessed, stored locally, and restored rather than being rebuilt, I don't see an obvious path to do that in the pull to refresh public api. Since storing/restoring is an efficiency concern, rather than a correctness issue, I don't think it's worth spending a lot of time on that.

It looks like there are defaults which passing an empty options object will use - and these include the specified options apart from passive: true.

Copy link
Contributor Author

@takmar takmar Oct 17, 2021

Choose a reason for hiding this comment

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

Thank you for your review!

I looked into pulltorefresh.js and found shouldPullToRefresh function which listed conditions for when to execute pulling to refresh. So I added this condition to shouldPullToRefresh instead of destroying the PullToRefresh object.

It looks like there are defaults which passing an empty options object will use - and these include the specified options apart from passive: true.

passive: true might be related to this. According to it, it could be better to specify passive: true if I call PullToRefresh's init().

if (typeof window.PullToRefresh !== 'undefined') {
document.body.dataset.leftNavState === 'open'
? window.PullToRefresh.destroyAll()
: window.PullToRefresh.init();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just repeating the code here for my own understanding, when calling toggleBurgerMenu (expanding the left nav menu), this will remove all setup PullToRefresh handlers via the public destroyAll function, and if we're toggling to closed, we set it back up.

I noticed the place we call init() originally, in base.js, we pass an option object

{
          mainElement: 'body',
          passive: true,
          onRefresh: function(){
            window.location.reload();
            }
         }

Do you think we should do that here as well? I'm not familiar with the code but the public api you're calling for init expects an object o and sets undefined to an empty object.

I assume these options should be reset when you call init() here. Or the existing options somehow accessed, stored locally, and restored rather than being rebuilt, I don't see an obvious path to do that in the pull to refresh public api. Since storing/restoring is an efficiency concern, rather than a correctness issue, I don't think it's worth spending a lot of time on that.

It looks like there are defaults which passing an empty options object will use - and these include the specified options apart from passive: true.

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 15, 2021
@takmar takmar force-pushed the takmar/fix_hamburger_menu_scrolling branch from 83eb4b8 to 140261f Compare October 17, 2021 03:19
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Oct 17, 2021
@takmar takmar force-pushed the takmar/fix_hamburger_menu_scrolling branch from 140261f to 8c26886 Compare October 17, 2021 05:44
Copy link
Contributor

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @takmar! 🚀

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 19, 2021
@nickytonline nickytonline merged commit e8d0416 into forem:main Oct 19, 2021
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Oct 19, 2021
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.

Forem mobile hamburger menu scrolling bug
4 participants