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

Commit 348f6c0

Browse files
clshortfusejelbourn
authored andcommitted
fix(tabs): properly blank activedescendant attr when no tabs exist (#9907)
`aria-activedescendant` should be blank if no tabs could be found * Add null check when searching for currently focused tab Fixes #9279
1 parent a1f2e17 commit 348f6c0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/components/tabs/js/tabsController.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
6363
ctrl.getTabElementIndex = getTabElementIndex;
6464
ctrl.updateInkBarStyles = $mdUtil.debounce(updateInkBarStyles, 100);
6565
ctrl.updateTabOrder = $mdUtil.debounce(updateTabOrder, 100);
66+
ctrl.getFocusedTabId = getFocusedTabId;
6667

6768
init();
6869

@@ -339,7 +340,7 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
339340
ctrl.offsetLeft = fixOffset(tab.offsetLeft);
340341
} else {
341342
/**
342-
* Canvas width *smaller* than tab width: positioning at the *end* of current tab to let
343+
* Canvas width *smaller* than tab width: positioning at the *end* of current tab to let
343344
* pagination "for loop" to proceed correctly on next tab when nextPage() is called again
344345
*/
345346
ctrl.offsetLeft = fixOffset(tab.offsetLeft + (tab.offsetWidth - viewportWidth + 1));
@@ -362,10 +363,10 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
362363
ctrl.offsetLeft = fixOffset(tab.offsetLeft + tab.offsetWidth - elements.canvas.clientWidth);
363364
} else {
364365
/**
365-
* Canvas width *smaller* than tab width: positioning at the *beginning* of current tab to let
366+
* Canvas width *smaller* than tab width: positioning at the *beginning* of current tab to let
366367
* pagination "for loop" to break correctly on previous tab when previousPage() is called again
367368
*/
368-
ctrl.offsetLeft = fixOffset(tab.offsetLeft);
369+
ctrl.offsetLeft = fixOffset(tab.offsetLeft);
369370
}
370371
}
371372

@@ -494,6 +495,17 @@ function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipp
494495
ctrl.offsetLeft;
495496
}
496497

498+
/**
499+
* Returns currently focused tab item's element ID
500+
*/
501+
function getFocusedTabId() {
502+
var focusedTab = ctrl.tabs[ctrl.focusIndex];
503+
if (!focusedTab || !focusedTab.id) {
504+
return null;
505+
}
506+
return 'tab-item-' + focusedTab.id;
507+
}
508+
497509
/**
498510
* Determines if the UI should stretch the tabs to fill the available space.
499511
* @returns {*}

src/components/tabs/js/tabsDirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function MdTabs ($$mdSvgRegistry) {
132132
'</md-next-button> ' +
133133
'<md-tabs-canvas ' +
134134
'tabindex="{{ $mdTabsCtrl.hasFocus ? -1 : 0 }}" ' +
135-
'aria-activedescendant="tab-item-{{$mdTabsCtrl.tabs[$mdTabsCtrl.focusIndex].id}}" ' +
135+
'aria-activedescendant="{{$mdTabsCtrl.getFocusedTabId()}}" ' +
136136
'ng-focus="$mdTabsCtrl.redirectFocus()" ' +
137137
'ng-class="{ ' +
138138
'\'md-paginated\': $mdTabsCtrl.shouldPaginate, ' +

0 commit comments

Comments
 (0)