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: fix SmoothScroll not applying custom options #11622

Merged
merged 3 commits into from
Dec 12, 2018

Conversation

ben-z
Copy link
Contributor

@ben-z ben-z commented Dec 7, 2018

Description

SmoothScroll no longer takes into account the options passed in to its constructor because the event handler doesn't have the correct this. It worked prior to v6.5 because before the refactor, the event handler uses _this from the closure instead of this directly.

Please refer to #11620 for a detailed description of this bug.

This PR binds this to the event handlers to solve the problem.

Types of changes

  • Documentation
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (anything that would change an existing functionality)
  • Maintenance (refactor, code cleaning, development tools...)

Checklist

  • I have read and follow the CONTRIBUTING.md document.
  • The pull request title and template are correctly filled.
  • The pull request targets the right branch (develop or develop-v...).
  • My commits are correctly titled and contain all relevant information.
  • I have updated the documentation accordingly to my changes (if relevant).
  • I have added tests to cover my changes (if relevant).

It's my first time contributing. As far as I know there aren't any unit tests for this, so I didn't add any tests for my changes. Please let me know if I need to do anything else for this PR!

Copy link
Contributor

@ncoden ncoden left a comment

Choose a reason for hiding this comment

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

With .bind(), a new function will be created and attached to the event. So when we want to clear the handlers in _destroy with this._handleLinkClick, the function will not be detached from the event.

You could save this._handleLinkClick.bind(this) as this._linkClickListenner then reuse it in _destroy to clear it.

@ben-z
Copy link
Contributor Author

ben-z commented Dec 7, 2018

@ncoden good catch! Fixed as suggested. Since _events seems to only be called from the constructor, I don't think we need to worry about this._linkClickListenner being overwritten when there are multiple calls to _events.

js/foundation.smoothScroll.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ncoden ncoden left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @ben-z 👍

@ncoden
Copy link
Contributor

ncoden commented Dec 10, 2018

Waiting for @DanielRuf to approve the changes as well.

@ncoden ncoden added this to the 6.5.2 milestone Dec 12, 2018
@ncoden ncoden merged commit 90d6b02 into foundation:develop Dec 12, 2018
ncoden pushed a commit that referenced this pull request Jan 11, 2019
ae8363a Fix smoothscroll not applying custom options
8dd7065 fix: correctly remove the event listener in _destroy
9767057 fix: fix spelling

Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
@ncoden ncoden mentioned this pull request Jan 12, 2019
11 tasks
@ben-z ben-z deleted the fix-smooth-scroll-options branch February 13, 2019 20:13
@ben-z ben-z restored the fix-smooth-scroll-options branch February 13, 2019 20:13
@ben-z ben-z deleted the fix-smooth-scroll-options branch February 13, 2019 20:14
@ben-z ben-z restored the fix-smooth-scroll-options branch February 13, 2019 20:14
@joeworkman
Copy link
Member

This pull request has been mentioned on Foundation Open Source Community. There might be relevant details there:

https://foundation.discourse.group/t/foundation-for-sites-v6-6-0-is-here-farout/30/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SmoothScroll options can't be set
4 participants