The point of the following is to open the discussion on keyboard-only access with respect to the grid. The main topics are navigation, keyboard focus, headers, and selections. This was written before looking at the grid's code or test files in order that I not be influenced by how the grid currently implements keyboard access. Since then, I've started to look at the gird in detail, and it looks to function close to what I've described. In that regard, is there a document that describes the keyboard "rules" for grid?
Outline
Navigation
Keyboard navigation is as follows (taken from the DHTML style guide section on tables, specifically the sub-section on standard tables [http://dev.aol.com/dhtml_style_guide#table]:
Keys for Standard Tables
- Tab
- The initial tab enters the grid with focus on the first header cell.
- Once in the grid a second tab moves out of the grid to the next tab stop.
- Once focus is established in the grid, a TAB into or a Shift Tab into the grid will return to the cell which last had focus.
- Left and Right Arrow Navigation between columns. If the next cell in the row is empty, focus should not move.
- Up and Down Arrow Navigation between Rows. If the next cell in the column is empty, focus should move to the first column in the next row. If the next cell in the column is not empty, focus should move directly to that cell
(Aside: the rules for "empty" cells is controversial. They are ignored in what follows).
Keyboard Focus
There is a general focus issue, namely, what has focus in a grid?
One possibility is to model grid after toolbar [http://dev.aol.com/dhtml_style_guide#toolbar] then the grid itself keeps focus, and the key presses are handled by the grid. As the user arrows from cell to cell, the key strokes are handled by the grid, and it styles the cell to make it appear focussed/selected.
Another scenario has individual cells obtaining focus as the user arrows among them. This is implied by the style guide quoted above (Keys for Standard Tables). It is also how the dijit colour palette widget works.
Note, however, that the contents of the cell introduces a wrinkle. If the cell contents is "data", and rendered as read-only text, then either of the above models will suffice. But, if the cell contains a widget or a hyperlink, then there are advantages if focus was on that widget. For the sake of discussion, when cell contents is a widget or a hyperlink, it is referred to here as "interactive content":
- If focus is on the interactive content, keyboard interaction with that content is already defined by the widget. For example, if the content is a hyperlink, then pressing <enter> will activate the link. If a checkbox, <space> will check or uncheck it. If a menu, the menu can be popped open, and navigated.
- Users will not readily see a distinction between a cell and, say, the checkbox inside it. They are apt to see the interactive content as the thing that has focus. If focus remains on the cell itself, then a keystroke is needed to move focus (in)to the interactive content, and another to move back up to the cell. Users will find this awkward (admittedly an armchair hypothesis).
One exception is where the cell's content is editable text. Here, initially, focus is on the cell. If enter is pressed, then the field becomes an editable text field, gains focus, and the keystrokes for a text field come into play. Note that text field could involve auto-completion with a popup of suggested values. Users confirm the final value with a <return>, the cell reverts to static text with the new value, and focus is once again on the cell. (Note: desktop spreadsheets do not behave this way. If a cell is editable, once focus is brought to it, one can add content to it. Pressing enter accepts the new value and moves focus to the cell immediately below).
There is a disadvantage with putting the focus on interactive content, namely, how does one navigate to another cell if the interactive content already handles arrow keystrokes. For example, if the cell contains a slider, left and right arrows are for moving the slider thumb, not for moving to the previous/next cell. There needs to be a way to move focus back up to the cell.
Column Headers
There is a need to inform user via a keystroke which column and row they are in when they have navigated to a particular cell. This includes any headers associated with the column and row.
Users also require quick navigation via a keystroke to the column headers. That is, no matter what cell the user is currrently in, they can move quickly to the top of the column. Similarly for navigating quickly to the beginning and end of the current row. I suggest <home> to move keyboard focus to the column header (meaning, "move to the top of the column"), and
Selections
When focus is on a cell, it is automatically "selected" as well.
There needs to be a keystroke to select the current row or column, but I have no suggestion yet.
After selecting a cell, extend the selection to neighbouring cells using <shift+arrow>.
Once there is a selection, it can be cut or copied using the usual keystrokes. Users may then move to another location in the grid, and paste the cut/copied cells.
Unfortunately, the keystrokes for extending the selection, cut, copy, and paste all potentially conflict with the focus rules above regarding interactive content, since that content itself may use these keystrokes when it has focus. It suggests that one needs to put focus on the cell, not on its contents. Nonetheless, the selection keystrokes could work if the interactive content has no handler for <shift+arrow>, which could then bubble up to the cell itself, where it would be detected as meaning "extend to selection of cells".

Moving focus and input widgets
I think you have a very valid point here:
I would very much prefer the "spreadsheet-like" focus model, where the user can edit the contents of an editable cell immediately after navigating into the cell. The other suggestion, where user needs to press a key to alternate between focus movement and editing, reminds me of the command and editing modes in the "vi" editor.
I actually have a dojo grid consisting of text fields where the navigation is done in the "spreadsheet-like" fashion, and the users do like it a lot.
A few comments on column headers
I don't think it is necessary to "inform user via a keystroke which column and row they are in when they have navigated to a particular cell." If we provide the correct ARIA information, the assistive technology (AT) can provide this to the user via an AT defined mechanism. A sighted user can determine this from the row and column borders.
Regarding setting focus into the column headers I suggest we use the same mechanism that is used for the editor and the associated toolbar. In the case of the editor, the toolbar is a tab stop and the editor is a tab stop. If focus is in the editor, pressing shift-tab puts focus into the toolbar. With focus in the toolbar, pressing tab puts focus back into the editor. With focus in the editor pressing tab gain moves focus to the next focusable item after the editor.
I think the grid could work the same. With focus on the focusable item before the grid, pressing tab puts focus into the left most column header of the grid. Pressing the left or right arrow will move between the column header cells. With focus in the left most column header, pressing up and down will move through the row headers if they exist. With focus in a cell, pressing shift-tab will move focus back to the left-most column header. With focus in a column/row header pressing tab again will move to the last focused cell in the grid (or the upper left cell if this is the first time the grid is receiving focus).
OPEN ISSUE: If the user moves focus from a cell back into the column header, navigates to a particular header cell and sorts that column. Pressing tab should move the user back to the previous cell - but what if, due to the sort, that cell is no longer visible? Should that previous cell be scrolled into view or should focus go to the cell at the same row and column index as the previously focused cell. My gut says that it should go back to the same cell and that it should be scrolled into view but I imagine there are cases where the position is more important. Thoughts?
The idea of using tab stops
The idea of using tab stops to move from the header to the cells and back is a good one. My intent was to avoid a "hot key" solution because of the controversy around the html access attribute and the new proposal under discussion; thus, the suggestion to use <home>. But, I'll gladly abandon <home> for the tab stop scenario.
Regarding where to return focus to after sorting the column, my intuition is the same: focus returns k to the last cell the user visited. I think that is what they would expect, although it might be slightly jarring that it has visually moved since their last visit.
more on focus
A few comments:
Yes, definitely in the common example you mentioned where the the cell contains a single checkbox. It's a different can of worms though if the content is something like a paragraph of text with two hyperlinks in it. Not sure what to do there; maybe it's just not allowed?
I thought that you had to hit space bar to start editing the content and then ESC when you are finished, like InlineEditBox. I understand the advantage of the spreadsheet model but that's not how we've currently implemented grid, anyway.
Can't you just require a checkbox in the first column like google mail or yahoo mail?
=========
Bill Keese
Project Lead (aka BDFL) of Dijit
Spreadsheet-like focus model
In addition to checkboxes, simple one-line input boxes (entering numbers, short strings etc) will benefit from a spreadsheet-like focus model.
Yes, when the interactive content is complex, then there needs to be a way to support accessibility.
Also, widgets should not need any new focus handling features in order to be embedded in a grid.
I think the "basic" focus model where you need to press a key to start editing probably needs to be done anyway, as the spreadsheet model can only work for some types of widgets.
Even if the spreadsheet model isn't implemented right now, it should be easy for programmers like me to implement it in our apps.
- Matti Haavikko