This repository was archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Accessibility for tab component #3908
Closed
+145
−27
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,7 @@ angular.module('ui.bootstrap.tabs', []) | |
* @restrict EA | ||
* | ||
* @param {string=} heading The visible heading, or title, of the tab. Set HTML headings with {@link ui.bootstrap.tabs.directive:tabHeading tabHeading}. | ||
* @param {string=} id The name of attribute used for refer to tab content. | ||
* @param {string=} select An expression to evaluate when the tab is selected. | ||
* @param {boolean=} active A binding, telling whether or not this tab is selected. | ||
* @param {boolean=} disabled A binding, telling whether or not this tab is disabled. | ||
|
@@ -192,6 +193,7 @@ angular.module('ui.bootstrap.tabs', []) | |
scope: { | ||
active: '=?', | ||
heading: '@', | ||
id : '@', | ||
onSelect: '&select', //This callback is called in contentHeadingTransclude | ||
//once it inserts the tab's content into the dom | ||
onDeselect: '&deselect' | ||
|
@@ -224,17 +226,20 @@ angular.module('ui.bootstrap.tabs', []) | |
}); | ||
} | ||
|
||
scope.select = function() { | ||
if ( !scope.disabled ) { | ||
scope.active = true; | ||
} | ||
}; | ||
|
||
tabsetCtrl.addTab(scope); | ||
scope.$on('$destroy', function() { | ||
tabsetCtrl.removeTab(scope); | ||
}); | ||
|
||
if ( attrs.id ) { | ||
elm.removeAttr('id'); | ||
} | ||
|
||
scope.select = function() { | ||
if ( !scope.disabled ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix code style |
||
scope.active = true; | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add new line after this line. |
||
//We need to transclude later, once the content container is ready. | ||
//when this link happens, we're inside a tab heading. | ||
scope.$transcludeFn = transclude; | ||
|
@@ -263,7 +268,6 @@ angular.module('ui.bootstrap.tabs', []) | |
require: '^tabset', | ||
link: function(scope, elm, attrs) { | ||
var tab = scope.$eval(attrs.tabContentTransclude); | ||
|
||
//Now our tab is ready to be transcluded: both the tab heading area | ||
//and the tab content area are loaded. Transclude 'em both. | ||
tab.$transcludeFn(tab.$parent, function(contents) { | ||
|
@@ -276,6 +280,7 @@ angular.module('ui.bootstrap.tabs', []) | |
} | ||
}); | ||
}); | ||
addNavigationHandler(elm); | ||
} | ||
}; | ||
function isTabHeading(node) { | ||
|
@@ -286,6 +291,47 @@ angular.module('ui.bootstrap.tabs', []) | |
node.tagName.toLowerCase() === 'data-tab-heading' | ||
); | ||
} | ||
|
||
function addNavigationHandler(tab) { | ||
var aElements = tab.parent().parent().find('ul').find('a'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is too heavily tied to the DOM structure - this needs to change. |
||
//set keydown events on tabList item for navigating and selection tabs | ||
aElements.on('keyup', function (e) { | ||
var aElement = e.target; | ||
var tabElement = aElement.parentNode; | ||
switch (e.which) { | ||
case 37: case 38: | ||
if (previousElementSibling(tabElement) != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix to |
||
previousElementSibling(tabElement).querySelector('a').focus(); | ||
} else { | ||
aElements[aElements.length - 1].focus(); | ||
} | ||
break; | ||
case 39: case 40: | ||
if (nextElementSibling(tabElement) !== null) { | ||
nextElementSibling(tabElement).querySelector('a').focus(); | ||
} else { | ||
aElements[0].focus(); | ||
} | ||
break; | ||
case 13: | ||
aElement.click(); | ||
} | ||
}); | ||
} | ||
|
||
function nextElementSibling(element) { | ||
do { | ||
element = element.nextSibling; | ||
} while (element && element.nodeType !== 1); | ||
return element; | ||
} | ||
|
||
function previousElementSibling(element) { | ||
do { | ||
element = element.previousSibling; | ||
} while (element && element.nodeType !== 1); | ||
return element; | ||
} | ||
}) | ||
|
||
; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
<li ng-class="{active: active, disabled: disabled}"> | ||
<a href ng-click="select()" tab-heading-transclude>{{heading}}</a> | ||
</li> | ||
<li ng-class="{active: active, disabled: disabled}" role="presentation"> | ||
<a href ng-click="$event.preventDefault(); select()" role="tab" tabindex="{{active ? 0 : -1}}" aria-selected="{{!!active}}" id="{{id}}" tab-heading-transclude>{{heading}}</a></li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<div> | ||
<ul class="nav nav-{{type || 'tabs'}}" ng-class="{'nav-stacked': vertical, 'nav-justified': justified}" ng-transclude></ul> | ||
<ul class="nav nav-{{type || 'tabs'}}" ng-class="{'nav-stacked': vertical, 'nav-justified': justified}" role="tablist" ng-transclude></ul> | ||
<div class="tab-content"> | ||
<div class="tab-pane" | ||
ng-repeat="tab in tabs" | ||
ng-class="{active: tab.active}" | ||
tab-content-transclude="tab"> | ||
ng-repeat="tab in tabs" | ||
ng-class="{active: tab.active}" | ||
role="tabpanel" | ||
tabindex="{{tab.active ? 0 : -1}}" | ||
aria-hidden="{{!tab.active}}" | ||
aria-labelledby="{{tab.id}}" | ||
tab-content-transclude="tab"> | ||
</div> | ||
</div> | ||
</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
@?