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

Commit

Permalink
fix(tabs): dont use focusin event on firefox
Browse files Browse the repository at this point in the history
Closes #781
  • Loading branch information
ajoslin committed Dec 3, 2014
1 parent a348e19 commit 5559ac6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/components/tabs/js/paginationDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function TabPaginationDirective($mdConstant, $window, $$rAF, $$q, $timeout) {
scope.$on('$mdTabsChanged', debouncedUpdatePagination);
angular.element($window).on('resize', debouncedUpdatePagination);

// Listen to focus events bubbling up from md-tab elements
tabsParent.on('focusin', onTabsFocusIn);
// Listen to focus events from md-tab elements
tabsCtrl.scope.$on('$materialTab.focus', onTabFocus);

scope.$on('$destroy', function() {
angular.element($window).off('resize', debouncedUpdatePagination);
Expand All @@ -46,14 +46,18 @@ function TabPaginationDirective($mdConstant, $window, $$rAF, $$q, $timeout) {
scope.$watch(tabsCtrl.selected, onSelectedTabChange);

// Allows pagination through focus change.
function onTabsFocusIn(ev) {
function onTabFocus(ev, tab) {
if (!state.active) return;

var tab = angular.element(ev.target).controller('mdTab');
var pageIndex = getPageForTab(tab);
if (pageIndex !== state.page) {
// If the focused element is on a new page, don't focus yet.
tab.element.blur();
// Firefox doesn't support synchronously stopping focus, so we have
// to do it asynchronously there...
setTimeout(function() {
tab.element.blur();
});
// Go to the new page, wait for the page transition to end, then focus.
setPage(pageIndex).then(function() {
tab.element.focus();
Expand Down
6 changes: 6 additions & 0 deletions src/components/tabs/js/tabItemDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ function MdTabDirective($mdInkRipple, $compile, $mdAria, $mdUtil, $mdConstant) {
tabsCtrl.remove(tabItemCtrl);
});

// We have to listen to each individual tab's focus event for pagination's sake,
// because `focusin` (the bubbled pre-focus event) is not supported in Firefox.
element.on('focus', function() {
tabsCtrl.scope.$broadcast('$materialTab.focus', tabItemCtrl);
});

if (!angular.isDefined(attr.ngClick)) {
element.on('click', defaultClickListener);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/tabs/js/tabsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function MdTabsController($scope, $element, $mdUtil) {

// Properties
self.$element = $element;
self.scope = $scope;
// The section containing the tab content $elements
self.contentArea = angular.element($element[0].querySelector('.md-tabs-content'));

Expand Down

0 comments on commit 5559ac6

Please sign in to comment.