question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tabs indicator being set incorrectly due to imprecise jQuery .width() use

See original GitHub issue

The calcRightPos function to determine the right attribute for the tabs indicator utilizes the jQuery .width() function: https://github.com/Dogfalo/materialize/blob/master/js/tabs.js#L25. jQuery’s width function is imprecise in it’s result. For example, we are using percents to specify the width of the tabs. The width of the active tab (el) when checking in dev tools is 643.52, but el.width() returns 644. The extra .5 pixels causes the calcRightPos to return a -.5px. This in turn causes the width of the content of the ul.tabs container to exceed the container width, which then makes the scrollbar appear:

https://dl.dropboxusercontent.com/u/184528/screenshot.png

A simple fix is to use the JS getBoundingClientRect() function:

var calcRightPos = function(el) { return $tabs_width - el.position().left - el[0].getBoundingClientRect().width - $this.scrollLeft(); };

It might be smart to use getBoundingClientRect() for everywhere width() is used ($tabs_width).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobqcommented, Apr 3, 2017

@Dogfalo this is a pretty severe issue for me. Is there a fix planned? If not, would you accept a PR?

0reactions
Dogfalocommented, Oct 11, 2017

Tabs no longer relies on jQuery so this issue will be fixed in v1

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery width getting wrong value - Stack Overflow
width(). I have 4 different textarea that need to resize according to the size of a div that contains them, so I call...
Read more >
14. Creating Interactive and Accessible Effects with JavaScript ...
Use an accordion widget in combination with the aria-hidden and aria-expanded states, the tablist , tab , and tabpanel roles, and the aria-labeledby ......
Read more >
Known issues - Relativity Documentation
There is a known issue with LSI categorization where adding more documents to the categorization set leads documents to become uncategorized.
Read more >
HTML Standard
Duplicate IDs lead to the wrong element being selected, with sometimes ... and incorporates the varied writing systems of the world, incorrect usage...
Read more >
Gravity Forms Change Log
Fixed issue when using a custom tab index and the post image field with all meta fields ... Added a form setting to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found