Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b26c01c

Browse files
enne30hansl
authored andcommitted
fix(tabs): scroll blocks in pagination (related to #5439) (#9457)
* Paged md-tabs scroll blocking (related to #5439) Fixes md-tabs scroll blocking happening when single tab is larger than containing canvas (e.g. tabs containing long text elements). * Code formatted according to style guidelines * Code formatting and added explanation comments
1 parent 3854c4a commit b26c01c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/components/tabs/js/tabsController.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,17 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
333333
tab = elements.tabs[ i ];
334334
if (tab.offsetLeft + tab.offsetWidth > totalWidth) break;
335335
}
336-
ctrl.offsetLeft = fixOffset(tab.offsetLeft);
336+
337+
if (viewportWidth > tab.offsetWidth) {
338+
//Canvas width *greater* than tab width: usual positioning
339+
ctrl.offsetLeft = fixOffset(tab.offsetLeft);
340+
} else {
341+
/**
342+
* Canvas width *smaller* than tab width: positioning at the *end* of current tab to let
343+
* pagination "for loop" to proceed correctly on next tab when nextPage() is called again
344+
*/
345+
ctrl.offsetLeft = fixOffset(tab.offsetLeft + (tab.offsetWidth - viewportWidth + 1));
346+
}
337347
}
338348

339349
/**
@@ -346,7 +356,17 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
346356
tab = elements.tabs[ i ];
347357
if (tab.offsetLeft + tab.offsetWidth >= ctrl.offsetLeft) break;
348358
}
349-
ctrl.offsetLeft = fixOffset(tab.offsetLeft + tab.offsetWidth - elements.canvas.clientWidth);
359+
360+
if (elements.canvas.clientWidth > tab.offsetWidth) {
361+
//Canvas width *greater* than tab width: usual positioning
362+
ctrl.offsetLeft = fixOffset(tab.offsetLeft + tab.offsetWidth - elements.canvas.clientWidth);
363+
} else {
364+
/**
365+
* Canvas width *smaller* than tab width: positioning at the *beginning* of current tab to let
366+
* pagination "for loop" to break correctly on previous tab when previousPage() is called again
367+
*/
368+
ctrl.offsetLeft = fixOffset(tab.offsetLeft);
369+
}
350370
}
351371

352372
/**

0 commit comments

Comments
 (0)