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

Commit 1063a92

Browse files
Splaktarmmalerba
authored andcommitted
fix(tabs): new tab animation broken by code to support IE11 (#11711)
<!-- Filling out this template is required! Do not delete it when submitting a Pull Request! Without this information, your Pull Request may be auto-closed. --> ## PR Checklist Please check that your PR fulfills the following requirements: - [x] The commit message follows [our guidelines](https://github.com/angular/material/blob/master/.github/CONTRIBUTING.md#-commit-message-format) - [ ] Tests for the changes have been added or this is not a bug fix / enhancement - [x] Docs have been added, updated, or were not required ## PR Type What kind of change does this PR introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [x] Bugfix [ ] Enhancement [ ] Documentation content changes [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Build related changes [ ] CI related changes [ ] Infrastructure changes [ ] Other... Please describe: ``` ## What is the current behavior? The scroll to new tab animation is broken. <!-- Please describe the current behavior that you are modifying and link to one or more relevant issues. --> Issue Number: Fixes #11689 ## What is the new behavior? The scroll to new tab animation is fixed for browsers other than IE. ## Does this PR introduce a breaking change? ``` [ ] Yes [x] No ``` <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. --> <!-- Note that breaking changes are highly unlikely to get merged to master unless the validation is clear and the use case is critical. --> ## Other information
1 parent 67826f5 commit 1063a92

File tree

6 files changed

+53
-58
lines changed

6 files changed

+53
-58
lines changed

package-lock.json

Lines changed: 12 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@
115115
"not bb <= 10",
116116
"not op_mob <= 12.1"
117117
]
118-
}
118+
}

src/components/tabs/demoDynamicTabs/script.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
previous = null;
3333
$scope.tabs = tabs;
3434
$scope.selectedIndex = 0;
35-
$scope.$watch('selectedIndex', function(current, old) {
35+
$scope.$watch('selectedIndex', function(newVal, oldVal) {
3636
previous = selected;
37-
selected = tabs[current];
38-
if (old + 1 && (old !== current)) {
39-
$log.debug('Goodbye ' + previous.title + '!');
37+
selected = tabs[newVal];
38+
if (oldVal + 1 && !angular.equals(oldVal, newVal)) {
39+
$log.log('Goodbye ' + previous.title + '!');
4040
}
41-
if (current + 1) {
42-
$log.debug('Hello ' + selected.title + '!');
41+
if (newVal + 1 > 0) {
42+
$log.log('Hello ' + selected.title + '!');
4343
}
4444
});
4545
$scope.addTab = function(title, view) {
@@ -52,4 +52,3 @@
5252
};
5353
}
5454
})();
55-

src/components/tabs/js/tabDirective.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
* @param {string=} label Optional attribute to specify a simple string as the tab label
2626
* @param {boolean=} ng-disabled If present and expression evaluates to truthy, disabled tab
2727
* selection.
28-
* @param {string=} md-tab-class Optional attribute to specify a class that will be applied to the tab's button
28+
* @param {string=} md-tab-class Optional attribute to specify a class that will be applied to the
29+
* tab's button
2930
* @param {expression=} md-on-deselect Expression to be evaluated after the tab has been
3031
* de-selected.
3132
* @param {expression=} md-on-select Expression to be evaluated after the tab has been selected.
@@ -36,7 +37,8 @@
3637
* @usage
3738
*
3839
* <hljs lang="html">
39-
* <md-tab label="My Tab" md-tab-class="my-content-tab" ng-disabled md-on-select="onSelect()" md-on-deselect="onDeselect()">
40+
* <md-tab label="My Tab" md-tab-class="my-content-tab" ng-disabled md-on-select="onSelect()"
41+
* md-on-deselect="onDeselect()">
4042
* <h3>My Tab content</h3>
4143
* </md-tab>
4244
*

src/components/tabs/js/tabsController.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
230230
* @param {string|number} left
231231
*/
232232
function handleOffsetChange (left) {
233-
var elements = getElements();
234233
var newValue = ((ctrl.shouldCenterTabs || isRtl() ? '' : '-') + left + 'px');
235234

236235
// Fix double-negative which can happen with RTL support
237236
newValue = newValue.replace('--', '');
238237

239-
angular.element(elements.paging).css($mdConstant.CSS.TRANSFORM, 'translate(' + newValue + ', 0)');
238+
angular.element(getElements().paging).css($mdConstant.CSS.TRANSFORM,
239+
'translate(' + newValue + ', 0)');
240240
$scope.$broadcast('$mdTabsPaginationChanged');
241241
}
242242

@@ -439,11 +439,11 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
439439
* Create an entry in the tabs array for a new tab at the specified index.
440440
* @param {Object} tabData tab to insert
441441
* @param {number} index location to insert the new tab
442-
* @returns {*}
442+
* @returns {Object} the inserted tab
443443
*/
444444
function insertTab (tabData, index) {
445445
var hasLoaded = loaded;
446-
var proto = {
446+
var proto = {
447447
getIndex: function () { return ctrl.tabs.indexOf(tab); },
448448
isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
449449
isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
@@ -455,24 +455,27 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
455455
},
456456
id: $mdUtil.nextUid(),
457457
hasContent: !!(tabData.template && tabData.template.trim())
458-
},
459-
tab = angular.extend(proto, tabData);
458+
};
459+
var tab = angular.extend(proto, tabData);
460+
460461
if (angular.isDefined(index)) {
461462
ctrl.tabs.splice(index, 0, tab);
462463
} else {
463464
ctrl.tabs.push(tab);
464465
}
465-
466466
processQueue();
467467
updateHasContent();
468+
468469
$mdUtil.nextTick(function () {
469470
updatePagination();
470471
setAriaControls(tab);
471472

472473
// if autoselect is enabled, select the newly added tab
473-
if (hasLoaded && ctrl.autoselect) $mdUtil.nextTick(function () {
474-
$mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
475-
});
474+
if (hasLoaded && ctrl.autoselect) {
475+
$mdUtil.nextTick(function () {
476+
$mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
477+
});
478+
}
476479
});
477480
return tab;
478481
}
@@ -576,17 +579,20 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
576579
});
577580

578581
shouldPaginate = canvasWidth < 0;
579-
// Work around width calculation issues on IE11 when pagination is enabled
580-
if (shouldPaginate) {
581-
getElements().paging.style.width = '999999px';
582-
} else {
583-
getElements().paging.style.width = undefined;
582+
// Work around width calculation issues on IE11 when pagination is enabled.
583+
// Don't do this on other browsers because it breaks scroll to new tab animation.
584+
if ($mdUtil.msie) {
585+
if (shouldPaginate) {
586+
getElements().paging.style.width = '999999px';
587+
} else {
588+
getElements().paging.style.width = undefined;
589+
}
584590
}
585591
return shouldPaginate;
586592
}
587593

588594
/**
589-
* Finds the nearest tab index that is available. This is primarily used for when the active
595+
* Finds the nearest tab index that is available. This is primarily used for when the active
590596
* tab is removed.
591597
* @param newIndex
592598
* @returns {*}

src/core/util/util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,14 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
901901
// The XMLSerializer API is supported on IE11 and is the recommended workaround.
902902
var serializer = new XMLSerializer();
903903
return serializer.serializeToString(element);
904-
}
904+
},
905+
906+
/**
907+
* Support: IE 9-11 only
908+
* documentMode is an IE-only property
909+
* http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
910+
*/
911+
msie: window.document.documentMode
905912
};
906913

907914
// Instantiate other namespace utility methods

0 commit comments

Comments
 (0)