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

MDL drawer toggle button dissappeared on turbolinks page change #10

Closed
gruberjl opened this issue Jul 29, 2016 · 4 comments
Closed

MDL drawer toggle button dissappeared on turbolinks page change #10

gruberjl opened this issue Jul 29, 2016 · 4 comments

Comments

@gruberjl
Copy link

My site has a navigation drawer that has a drawer toggle button in the top left. Code: https://getmdl.io/components/index.html#layout-section/layout

Every time I followed a link the button to toggle the drawer would disappear. MDL is adding the button using JS on page load. When turbolinks changed pages, MDL wasn't recognizing the page change and adding the button back in.

As a quick fix you can add the following code to your project JavaScript.

document.addEventListener('page:change', function() { componentHandler.upgradeDom(); });
document.addEventListener('turbolinks:load', function() { componentHandler.upgradeDom(); });

I forked the project and added the above lines of code to material.js. Using the forked changes, users won't have to add the code to their projects.

@rubysamurai
Copy link
Owner

rubysamurai commented Jul 29, 2016

Hello,
Thanks for the PR, but turbolinks compatibility fix probably shouldn't be hacked into actual MDL code, unless MDL team decides to natively support turbolinks.

Calling componentHandler.upgradeDom() from material.js file wouldn't solve the turbolinks issue for those, who chose modular JavaScript components load, for example. And for those projects without turbolinks extra calls are redundant.

But thanks for bringing attention to this subject, this is definetly a major use case for developers using this gem and I will add a note in README with basic code examples for turbolinks v2/5 fixes.

@gruberjl
Copy link
Author

Great point. I shouldn't have thrown my quick hack in a pull request. I've never made a gem before so I'm not sure how you would perform an "if using turbolinks then do..."

@smd686s
Copy link

smd686s commented Jul 30, 2016

It would be good to add your change to the docs.

On Jul 29, 2016 9:46 PM, "John" notifications@github.com wrote:

Great point. I shouldn't have thrown my quick hack in a pull request. I've
never made a gem before so I'm not sure how you would perform an "if using
turbolinks then do..."


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#10 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAQtkm4s1IlFhqfYWPchnZhWRuVrmLLMks5qarr2gaJpZM4JYayz
.

@rubysamurai
Copy link
Owner

Now Ruby on Rails section of README includes a note on turbolinks compatibility with quick fixes examples.

Let me know, please, if it should be reworded better or anything is missing.

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

No branches or pull requests

3 participants