From 12627f5e39eb0afcf86be546f6818b4397c55fbc Mon Sep 17 00:00:00 2001 From: conzett Date: Tue, 22 Nov 2011 20:14:55 -0500 Subject: [PATCH] Add tests and code for aria-hidden attributes on tabpanels --- javascripts/tabs.js | 20 +++++++++++++------- javascripts/tests/tests.js | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/javascripts/tabs.js b/javascripts/tabs.js index a15a05d..de09e11 100644 --- a/javascripts/tabs.js +++ b/javascripts/tabs.js @@ -48,6 +48,13 @@ $(this).attr('role', 'tab'); }); + // if there isn't already a selected tab, make the first one selected + + if($(tabList).find('[aria-selected="true"]').length == 0) + { + $(tabs).first().attr('aria-selected', 'true'); + } + $(tabPanels).each(function(index) { var id = $(this).attr('id'); @@ -60,14 +67,13 @@ $(this).attr('aria-labeledby', $(tabs[index]).attr('id')); $(tabs[index]).attr('aria-controls', $(this).attr('id')); - }); + if($(tabs[index]).attr('aria-selected') == 'true'){ + $(this).attr('aria-hidden', 'false'); + }else{ + $(this).attr('aria-hidden', 'true'); + } - // if there isn't already a selected tab, make the first one selected - - if($(tabList).find('[aria-selected="true"]').length == 0) - { - $(tabs).first().attr('aria-selected', 'true'); - } + }); }; diff --git a/javascripts/tests/tests.js b/javascripts/tests/tests.js index 1c1d289..d2a6923 100644 --- a/javascripts/tests/tests.js +++ b/javascripts/tests/tests.js @@ -158,6 +158,27 @@ $(document).ready(function () { 'Expect tab at position ' + index + ' to match panel id at position ' + index); }); - }); + }); + + test("Aria-hidden attribute generation on tabpanels", function () { + + var tabContainer = $('#qunit-fixture #tab-container'); + var tabList = $(tabContainer).find('> ul'); + var tabPanels = $(tabContainer).children().not('ul'); + tabContainer.skeletonTabs(); + + $(tabPanels).each(function(index) { + if(index != 0){ + equals($(this).attr('aria-hidden'), + 'true', + 'Expect tabpanel at position ' + index + ' to have aria-hidden set to true'); + }else{ + equals($(this).attr('aria-hidden'), + 'false', + 'Expect tabpanel at position ' + index + ' to have aria-hidden set to false'); + } + }); + + }); }); \ No newline at end of file