Skip to content

Commit

Permalink
Layout Grid Example: Show Keyboard NUX only if Grid Focused With Tab Key
Browse files Browse the repository at this point in the history
Introduce an enhancement for the layout grid example review in issue #227.

The first layout grid provides a NUX to help new keyboard users understand that arrow keys can be used to navigate. This change will cause the NUX to be displayed only if the grid receives focus via the tab key.
  • Loading branch information
tatermelon authored and mcking65 committed Mar 9, 2017
1 parent a603344 commit a00c079
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/grid/LayoutGrids.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h4 id="grid1_label">Related Documents</h4>
<span role="gridcell" class="list-link"><a tabindex="-1" href="https://www.w3.org/TR/2015/WD-SVG2-20150915/">SVG 2 Specification</a></span>
</div>
</div>
<div id="grid-nux" class="grid-nux" role="region" aria-label="Grid Instructions" tabindex="0">
<div id="grid-nux" class="grid-nux hidden" role="region" aria-label="Grid Instructions" tabindex="0">
<p>
Move keyboard focus inside a grid with arrow keys.
</p>
Expand Down
20 changes: 14 additions & 6 deletions examples/grid/js/layoutGrids.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ window.addEventListener('load', function () {
);

var gridNUX = document.getElementById('grid-nux');
var firstGridCell = document.querySelector('#ex1 [tabindex="0"]');
firstGridCell.addEventListener(
'focus',
function () {
aria.Utils.removeClass(gridNUX, 'hidden');
},
{
once: true
}
);

var NUXclose = document.getElementById('close-nux-button');
var closeNUX = function () {
var cellToRefocus = document.querySelector('#ex1 [tabindex="0"]');
gridNUX.className = 'grid-nux hidden';
aria.Utils.addClass(gridNUX, 'hidden');
try {
cellToRefocus.focus();
} catch (error) {

}
firstGridCell.focus();
} catch (error) { }
};
NUXclose.addEventListener('click', closeNUX);
NUXclose.addEventListener('keyup', function (event) {
Expand Down

0 comments on commit a00c079

Please sign in to comment.