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

Commit

Permalink
fix(tabs): new tab animation broken by code to support IE11
Browse files Browse the repository at this point in the history
fix for browsers other than IE

Fixes #11689
  • Loading branch information
Splaktar committed Apr 19, 2019
1 parent 16cea88 commit f2dbe07
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 58 deletions.
43 changes: 12 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@
"not bb <= 10",
"not op_mob <= 12.1"
]
}
}
13 changes: 6 additions & 7 deletions src/components/tabs/demoDynamicTabs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
previous = null;
$scope.tabs = tabs;
$scope.selectedIndex = 0;
$scope.$watch('selectedIndex', function(current, old) {
$scope.$watch('selectedIndex', function(newVal, oldVal) {
previous = selected;
selected = tabs[current];
if (old + 1 && (old !== current)) {
$log.debug('Goodbye ' + previous.title + '!');
selected = tabs[newVal];
if (oldVal + 1 && !angular.equals(oldVal, newVal)) {
$log.log('Goodbye ' + previous.title + '!');
}
if (current + 1) {
$log.debug('Hello ' + selected.title + '!');
if (newVal + 1 > 0) {
$log.log('Hello ' + selected.title + '!');
}
});
$scope.addTab = function(title, view) {
Expand All @@ -52,4 +52,3 @@
};
}
})();

6 changes: 4 additions & 2 deletions src/components/tabs/js/tabDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
* @param {string=} label Optional attribute to specify a simple string as the tab label
* @param {boolean=} ng-disabled If present and expression evaluates to truthy, disabled tab
* selection.
* @param {string=} md-tab-class Optional attribute to specify a class that will be applied to the tab's button
* @param {string=} md-tab-class Optional attribute to specify a class that will be applied to the
* tab's button
* @param {expression=} md-on-deselect Expression to be evaluated after the tab has been
* de-selected.
* @param {expression=} md-on-select Expression to be evaluated after the tab has been selected.
Expand All @@ -36,7 +37,8 @@
* @usage
*
* <hljs lang="html">
* <md-tab label="My Tab" md-tab-class="my-content-tab" ng-disabled md-on-select="onSelect()" md-on-deselect="onDeselect()">
* <md-tab label="My Tab" md-tab-class="my-content-tab" ng-disabled md-on-select="onSelect()"
* md-on-deselect="onDeselect()">
* <h3>My Tab content</h3>
* </md-tab>
*
Expand Down
38 changes: 22 additions & 16 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
* @param {string|number} left
*/
function handleOffsetChange (left) {
var elements = getElements();
var newValue = ((ctrl.shouldCenterTabs || isRtl() ? '' : '-') + left + 'px');

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

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

Expand Down Expand Up @@ -439,11 +439,11 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
* Create an entry in the tabs array for a new tab at the specified index.
* @param {Object} tabData tab to insert
* @param {number} index location to insert the new tab
* @returns {*}
* @returns {Object} the inserted tab
*/
function insertTab (tabData, index) {
var hasLoaded = loaded;
var proto = {
var proto = {
getIndex: function () { return ctrl.tabs.indexOf(tab); },
isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
Expand All @@ -455,24 +455,27 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
},
id: $mdUtil.nextUid(),
hasContent: !!(tabData.template && tabData.template.trim())
},
tab = angular.extend(proto, tabData);
};
var tab = angular.extend(proto, tabData);

if (angular.isDefined(index)) {
ctrl.tabs.splice(index, 0, tab);
} else {
ctrl.tabs.push(tab);
}

processQueue();
updateHasContent();

$mdUtil.nextTick(function () {
updatePagination();
setAriaControls(tab);

// if autoselect is enabled, select the newly added tab
if (hasLoaded && ctrl.autoselect) $mdUtil.nextTick(function () {
$mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
});
if (hasLoaded && ctrl.autoselect) {
$mdUtil.nextTick(function () {
$mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
});
}
});
return tab;
}
Expand Down Expand Up @@ -576,17 +579,20 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
});

shouldPaginate = canvasWidth < 0;
// Work around width calculation issues on IE11 when pagination is enabled
if (shouldPaginate) {
getElements().paging.style.width = '999999px';
} else {
getElements().paging.style.width = undefined;
// Work around width calculation issues on IE11 when pagination is enabled.
// Don't do this on other browsers because it breaks scroll to new tab animation.
if ($mdUtil.msie) {
if (shouldPaginate) {
getElements().paging.style.width = '999999px';
} else {
getElements().paging.style.width = undefined;
}
}
return shouldPaginate;
}

/**
* Finds the nearest tab index that is available. This is primarily used for when the active
* Finds the nearest tab index that is available. This is primarily used for when the active
* tab is removed.
* @param newIndex
* @returns {*}
Expand Down
9 changes: 8 additions & 1 deletion src/core/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,14 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
// The XMLSerializer API is supported on IE11 and is the recommended workaround.
var serializer = new XMLSerializer();
return serializer.serializeToString(element);
}
},

/**
* Support: IE 9-11 only
* documentMode is an IE-only property
* http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
*/
msie: window.document.documentMode
};

// Instantiate other namespace utility methods
Expand Down

0 comments on commit f2dbe07

Please sign in to comment.