diff --git a/examples/treegrid/js/treegrid-row-nav-primary-1.js b/examples/treegrid/js/treegrid-row-nav-primary-1.js index ec8eb51fd0..0f7c6d27b7 100644 --- a/examples/treegrid/js/treegrid-row-nav-primary-1.js +++ b/examples/treegrid/js/treegrid-row-nav-primary-1.js @@ -1,8 +1,9 @@ -function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { +/* exported TreeGrid */ +function TreeGrid (treegridElem, doAllowRowFocus, doStartRowFocus) { function initAttributes () { // Make sure focusable elements are not in the tab order // They will be added back in for the active row - setTabIndexOfFocusableElems(treegrid, -1); + setTabIndexOfFocusableElems(treegridElem, -1); // Add tabindex="0" to first row, "-1" to other rows // We will use the roving tabindex method since aria-activedescendant @@ -44,7 +45,7 @@ function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { } function getAllRows () { - var nodeList = treegrid.querySelectorAll('tbody > tr'); + var nodeList = treegridElem.querySelectorAll('tbody > tr'); return Array.prototype.slice.call(nodeList); } @@ -65,7 +66,7 @@ function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { } function getAllNavigableRows () { - var nodeList = treegrid.querySelectorAll('tbody > tr:not([aria-hidden="true"])'); + var nodeList = treegridElem.querySelectorAll('tbody > tr:not([aria-hidden="true"])'); // Convert to array so that we can use array methods on it return Array.prototype.slice.call(nodeList); } @@ -83,7 +84,7 @@ function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { } function focus (elem) { - elem.tabIndex = -1; // Ensure focusable + elem.tabIndex = 0; // Ensure focusable elem.focus(); } @@ -98,7 +99,8 @@ function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { // one treegrid item to another function onFocusIn (event) { var newTreeGridFocus = - event.target !== window && treegrid.contains(event.target) && event.target; + event.target !== window && treegridElem.contains(event.target) + && event.target; // The last row we considered focused var oldCurrentRow = enableTabbingInActiveRowDescendants.tabbingRow; @@ -154,8 +156,8 @@ function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { function getContainingRow (start) { var possibleRow = start; - if (treegrid.contains(possibleRow)) { - while (possibleRow !== treegrid) { + if (treegridElem.contains(possibleRow)) { + while (possibleRow !== treegridElem) { if (possibleRow.localName === 'tr') { return possibleRow; } @@ -501,34 +503,11 @@ function onReady (treegrid, doAllowRowFocus, doStartRowFocus) { } initAttributes(); - treegrid.addEventListener('keydown', onKeyDown); - treegrid.addEventListener('click', onClick); - treegrid.addEventListener('dblclick', onDoubleClick); + treegridElem.addEventListener('keydown', onKeyDown); + treegridElem.addEventListener('click', onClick); + treegridElem.addEventListener('dblclick', onDoubleClick); // Polyfill for focusin necessary for Firefox < 52 window.addEventListener(window.onfocusin ? 'focusin' : 'focus', onFocusIn, true); } -// Get an object where each field represents a URL parameter -// e.g. { tab: 33 } -function getQuery () { - if (!getQuery.cached) { - getQuery.cached = {}; - const queryStr = window.location.search.substring(1); - const vars = queryStr.split('&'); - for (let i = 0; i + +
@@ -40,9 +89,9 @@

Treegrid Email Inbox Example

This same example can be used in three ways.

Note: no row-only version is provided. A row-only navigation version could be useful when the columns are guaranteed to fit horizontally (no horizontal scrolling necessary), the columns are merely for attractive presentation, as opposed to addressing any need to visit them individually. However, in this case the author can simply follow the tree pattern and present the child treeitem data in columns. @@ -354,11 +403,11 @@

Javascript and CSS Source Code