material icon indicating copy to clipboard operation
material copied to clipboard

md-tabs: Scrolls to top of page when tab is clicked

Open SmoshySmosh opened this issue 11 years ago • 19 comments

Clicking a new tab while using md-tabs will switch the tab but will also scroll the browser to the top of the page. Is this expected?

Tested on:

  • Chrome
  • Firefox
  • Safari

Replicate: Codepen: http://codepen.io/anon/pen/pJXYbX

  1. Scroll to bottom
  2. Press Tab 3
  3. Notice it scrolls to the top.

Note: In this example only tab 3 does it. But it consistently happens when clicking any tab in my project.

SmoshySmosh avatar Aug 22 '15 04:08 SmoshySmosh

+1

Also encountering this issue.

abramz avatar Aug 22 '15 04:08 abramz

Not happening to me, what browser versions?

nathanmarks avatar Aug 22 '15 12:08 nathanmarks

@SmoshySmosh It's scrolling me to the top of the tab but not the top of the page

nathanmarks avatar Aug 22 '15 12:08 nathanmarks

@nathanmarks Looking at it again, you're right. On my site it looked like it scrolled all the way to the top of the page because you can just barely see the top of the tabs after you click to a new tab.

Still though, the problem remains that this is scrolling is unwanted and problematic for people who are trying to display important content with the md-tabs component.

SmoshySmosh avatar Aug 22 '15 14:08 SmoshySmosh

I'm also seeing this issue on Firefox and Chrome.

angular-material 0.10.1 and angular 1.4.3.

chazzlabs avatar Aug 24 '15 14:08 chazzlabs

I'm seeing this as well. For me it only happens when clicking on tabs further to the right. Clicking on a tab to the left of the active tab does not seem to trigger a scroll to the top.

chris-jana avatar Aug 25 '15 22:08 chris-jana

This appears to be resolved now.

robertmesserle avatar Oct 06 '15 21:10 robertmesserle

Reproduces in 0.11.4

yarick333 avatar Oct 16 '15 13:10 yarick333

@yarick333 - CodePen Demo please.

ThomasBurleson avatar Oct 16 '15 13:10 ThomasBurleson

http://codepen.io/anon/pen/ojogER it only happens when clicking on tabs further to the right. Clicking on a tab to the left of the active tab does not seem to trigger a scroll to the top.

yarick333 avatar Oct 16 '15 14:10 yarick333

@robertmesserle - can your review ?

ThomasBurleson avatar Oct 16 '15 14:10 ThomasBurleson

You need to add CSS:

.tabsdemoDynamicHeight md-content md-tabs {
    border: 1px solid #e1e1e1; 
}

All work then

yarick333 avatar Oct 16 '15 14:10 yarick333

Looking into this now. This only happens when md-dynamic-height is enabled, which makes me think it is due to a brief period where there is no content height while switching tabs. Looking into a way to make sure the height never flashes to 0 during this time.

robertmesserle avatar Oct 29 '15 20:10 robertmesserle

I agree that it shouldn't scroll to the top of the entire page, but it should scroll to the top of the tabs themselves?

referring to my issue #5239

blakemanzo avatar Oct 31 '15 02:10 blakemanzo

I have the same "scrolling to the top" problem on v1.0.6 for Safari when md-dynamic-height is enabled. On Chrome, it is working perfectly. Not very user friendly and quiet problematic for Safari users. Is there any turn around or fix ? I tried the fix proposed by @robertmesserle but it doesn't worked for me... Any idea guys ?

manuelagard avatar Mar 17 '16 08:03 manuelagard

I opened a new issue #8065 showing the same problem with an animated gif. Tested on the actual Angular Material Demo website : https://material.angularjs.org/0.11.2/#/demo/material.components.tabs

Angular Material : Version 1.1.0-RC4 Angular : Version 1.4.8 Safari : Version 9.1

manuelagard avatar Apr 19 '16 13:04 manuelagard

Problem still exists but only when tabs are paginated (with md-dynamic-height)... Using 1.1.0 RC5 with chrome...

r0b- avatar Jun 20 '16 21:06 r0b-

+1

immersionfx avatar Jul 08 '16 08:07 immersionfx

Problem seems to be fixed in Chrome 63, but present in Firefox 57.0.4.

AM 1.1.6. Angular 1.5 (Ionic bundled 1.3.2) Firefox 57.0.4 Mac OS X El Capitan

Only with md-tabs with md-dynamic-height as @r0b- stated. Oddly, it only happens when clicking from the first tab to another. Clicking from any other tab to any other tab doesn't trigger the scroll to top.

CONFIRMED, disabling the first tab with ng-disabled="$index == 0" fixes the issue in Firefox.

So a dirty work-around could be: disable the first tab (ng-disabled), and hide it with CSS (display:none — ng-show does not play well with ng-disabled). Of course you'll have to fix your ng-repeat accordingly, as well as your indexes or ids, since the first tab will now be a "ghost".

<md-tab 
ng-repeat="item in data.items track by $index"
label="Item n°{{ $index }}"
ng-if="$index <= data.maximum_items"
ng-disabled="$index == 0"
ng-class="{'display_none': $index == 0}"
>


...

.md-tab.md-disabled{
	display: none !important;
}

bonatoc avatar Jan 23 '18 18:01 bonatoc