Data grid / foldkit-mixins-data-grid
What it draws
| Slot | Role and key attributes |
|---|---|
root | role="grid", tabindex="0", aria-rowcount, aria-colcount, aria-activedescendant |
header | role="rowgroup", sticky at top of the scroll container |
headerRow | role="row", aria-rowindex="1" |
headerCell | role="columnheader", aria-colindex |
resizeHandle | role="separator", column width as aria-valuenow |
body | role="rowgroup", full virtual height of all rows |
row | role="row", logical aria-rowindex (2 for first data row) |
cell | role="gridcell", aria-colindex, cell DOM id |
placeholder | placeholder row while counted rows are still loading |
status | status banner (shows "No rows." when empty) |
- Counts and indexes are logical.
aria-rowcountis every row plus the header, or-1when the count is unknown;aria-rowindexandaria-colindexare a cell's place among all rows and visible columns, so a screen reader says "row 5,002" of a window that holds twenty. - One tab stop. DOM focus stays on
root, andaria-activedescendantnames the current cell while it is drawn. A cell scrolled out of the window is gone from the DOM, so the attribute is left off until it is back. - Keys are
GridFocus.target's: arrows, Home and End, Ctrl for the corners, PageUp and PageDown by the rows the viewport holds. A key the grid does not handle (Enter, Tab, anything with Shift, Alt or Meta) keeps its default. - Resize handles sit at each resizable column's end edge. A pointer drag
resizes from where it began (the header row's one listener follows it, as
it follows a header dragged to reorder), and a cancelled pointer (
pointercancel, or a lost capture) puts the width back; a focused handle steps 16px with the arrow keys, its own keys only, so the grid's focus stays put. Handles are out of the tab order, so the grid stays one tab stop. - Selection, when the grid has it: rows say
aria-selectedwithrowSelection, cells in the range say it withcellSelection, and the grid isaria-multiselectablefor either kind of several. The pointer goes through one listener on the body: a click focuses a cell, Shift with a click spans a range from the focused cell, and Ctrl or Meta with a click toggles the cell's row. On the keyboard, Shift with an arrow, a page, Home or End moves a range's far corner (scrolling it into view), Space selects the focused row and Shift+Space extends the rows to it, Ctrl or Meta with A selects every row (or every cell), and Escape lets a range go. - Undo and redo keys. Ctrl or Meta with Z sends
UndoRequested, with Shift (or Ctrl+Y)RedoRequested; the application keeps the history. Keys in an open editor stay the input's. - Fill, in a grid that edits. Ctrl or Meta with D carries the range's
first row down it (a lone cell or one row, the row above), with R its
first column across it. The
fillHandleSlot, a square at the end corner of the range or the focused cell, is dragged to fill along one axis; the cells it would write saydata-fill="target"until it is let go, and Escape lets it go back. The handle is pointer-only and hidden from assistive technology, since the keys do the same. Held near the grid's edge or past it, the drag scrolls the grid that way and fills on into the rows it brings in. - The header row is part of the grid. ArrowUp from the first row goes up
to the header (
aria-activedescendantnames the header cell), the arrows and Home and End walk it, ArrowDown or Escape go back to the row focus came from. On a header, Shift with an arrow resizes the column 16px, and Ctrl or Meta with Shift and an arrow moves it within its region; both are mirrored in right-to-left text. - The editor follows the column's schema (
Grid.editorFor): a schema whose text is one of a few literals (Schema.Literals) is a choice of them: arole="combobox"showing the draft (thechoiceslot) beside itsrole="listbox"(choiceList,choiceOption), drawn by the grid and styled with the page. It opens on the cell's value, below the cell or above it when the cell is low in the view; the arrows, Home, End and the page keys walk it, a letter finds the next option it starts, Enter and Tab keep the draft and move on, Alt+ArrowUp keeps it in place, Escape drops it, and a press on an option chooses it. WithchoiceEditor: 'native'it is the platform'sselect, whose picker suits a touch screen, its list open at once where the browser allows (showPicker). One that decodes to a number is a text field with a decimal keypad on touch; anything else is text (editor). - A checkbox, for a column whose schema decodes to a boolean
(
Columns.checkbox): the cell holds arole="checkbox"(thecheckboxslot) whosearia-checkedis the column's value and whose name is the column's header, in place of the cell's text (and ofcell). A plain press on the box, or Space or Enter on the focused cell, sendsEditToggled, and no field opens; Space toggles here rather than selecting the row. A press with Shift, Ctrl, Meta or Alt is the cell's, as on any cell, and so is a press on arole="checkbox"an application draws withcell: only the grid's own box toggles. Focus stays on the grid, so the box is never a tab stop; while its cell is the focused one,aria-activedescendantnames the box rather than the cell, since the cell has no checked state to say. A checkbox cell has nodata-editable(no text cursor) and no double-click edit.GridStyledraws a box the size of the text, filled with the accent and ticked when checked. - Editing, for a column with
edit: Enter, F2 or a double-click opens a text field in the cell on its text, and a printable key opens it on that character (EditTyped); keys typed before the field is drawn add to it, and Escape before then cancels it. In the field, Enter commits and moves down (Shift+Enter up), Tab commits and moves across (Shift+Tab back), and Escape cancels; the arrows are the field's own. Focus leaving the field (a click elsewhere) commits it, as Enter does without moving. A draft the column'sschemarefuses stays open witharia-invalid, and its error is shown below the field (editorError,role="alert", which the field names witharia-describedby), until the draft is fixed or Escape drops it. Focus comes back to the grid when the field goes. Clicking another cell commits first. In a grid where some columns edit, the others' headers and cells carryaria-readonly, whichGridStyledraws as a padlock before the header's label and muted text in the cells (a grid where nothing edits marks nothing). An editable cell carriesdata-editable(GridStylegives it a text cursor), and the cell being editeddata-editing, whichGridStylelifts with a shadow and hands its padding to the field, outlined in the focus colour with a caret of it, so an edit does not look like a cell that only has focus. - The clipboard works on the range, or the focused cell. Copy puts it on
the clipboard as tab-separated text, as spreadsheets read it, and as an
HTML table (
text/html, cells escaped) for a target that reads that, and the application hears oneOut.Copied({ rows, columns }); paste lays text from the range's corner onto editable cells and the application hears oneOut.Pasted; cut copies and clears the editable cells, and Delete or Backspace clears them without copying. While a cell is edited, the field has the clipboard. - Where the rows stand, from
status(GridCrud.statusfor a Remote page): the grid isaria-busywhile loading or refreshing; with no rows it says loading, or the failure with a retry whenonRetryis given; with rows, a failure is said in thefooter, below them.GridStyleshows the loading line only once the wait is noticeable (Utilities.busyRevealfromfoldkit-mixins/utilities), its space held. While there are no rows and no answer (loading, or failed with nothing kept),aria-rowcountis-1, the count not known, rather than an empty grid's.onMoreputs a More button in the footer while the count is not known. AttachMoreOnScroll(DataGridView<Message>().define(Grid).pipe(MoreOnScroll)) and the button also sends it when it comes within 200px of the grid's visible box, and again after each load while it stays there. Nothing is asked while the grid is busy, so givestatustoo: without it, the button asks again each time it comes back into view before the page lands. - The column menu, with
columnMenu: true: each header has a button (menuButton,aria-haspopup="menu") that opens arole="menu"below it, listingGrid.menuItems: pin to the start or the end or unpin, hide, and show each hidden column. On a focused header Shift+F10 or the menu key opens it, and Alt+ArrowDown on a column that does not filter (on one that does, Alt+ArrowDown opens its filter). The menu takes focus and points at its active item witharia-activedescendant; the arrows, Home and End walk it, Enter or Space or a click runs an item, and Escape, a choice, or focus leaving closes it, focus going back to the grid unless the user sent it elsewhere. Its words aremenu,pinStart,pinEnd,unpin,hideandshowinwords. - Marks are the application's states on single cells, such as an edit
not yet saved:
marks: address => Option.some({ name, description }). The name is drawn asdata-markon the cell's Slot, which the default style gives a dot in the corner and an application styles by name (&[data-mark="refused"]in its ownStyle.forSlots(GridSlots)), and the description is the cell'saria-description, so a screen reader says what the dot shows. It is asked only for the cells drawn. Five names are shared, for a grid over a server (GridMarks:pending,saved,refused,replaced,peer):GridMarkStyle, attached afterGridStyle, draws them on the theme's tokens, a shape for each, not only a colour (and an outline where colours are forced), with a peer's colour from--fk-grid-peerwhen the application sets one.GridLegend<Message>()draws what they mean, each beside a swatchGridLegendStylepaints with the cells' own rules, so the two cannot disagree. - Sorting is the application's:
sortgives a column its direction and the Message that sorts it next (foldkit-crud'sSorthas this shape). The header saysaria-sort, and its label is a button the pointer sorts with, markeddata-sort(ascordesc) while sorted, whichGridStyledraws as a small chevron after the label; its place is kept while unsorted, so sorting moves nothing, and a header label never wraps. Enter on the focused header sends it too.GridStyleparts columns with a faint line, which on a header is the resize handle, darker under the pointer. - Filters are the application's, as sorting is: a column with
filter(foldkit-data-grid) needsfilters, the application'sGrid.Filtersvalue, and a grid with none refuses it (FiltersInput). Each such header draws afilterButton(aria-haspopup="dialog", named "Filter {column}", out of the tab order), and Alt+ArrowDown on the focused header opens the same form, advertised as the header'saria-keyshortcuts. The form is afilterSlot, a non-modalrole="dialog"in the header cell, holding native fields for the column's kind: a text field ("Contains"), two bounds ("At least", "At most", typed with a decimal keypad), a choice's checkboxes in arole="group", a checkbox column's radios (Any, Checked, Unchecked) in arole="radiogroup", or two days ("From", "To"). Its first field takes focus; it applies as it is typed, with no Apply button; a bound that is no number, or an upper bound below the lower, isaria-invalidand described by afilterError;filterClearempties it while a filter holds. Escape closes it, focus going back to the grid on its header, and so does focus leaving the header; a press on the filter button while it is open stays inside and closes it. While a column is filtered its header and button carrydata-filtered, and the header says "Filtered" as itsaria-description("Read-only, Filtered" on a column that does not edit, whose title's description it replaces;words.readOnlyis that word, here and in thetitlea column that does not edit shows on hover). Every header is named by its own words (aria-label), so neither its buttons nor an open form join its name. While the form is open the grid's clipboard handlers are off, so copy, cut and paste in its fields are the fields' own. The words arewords.filters; the Slots arefilterButton,filter,filterLabel,filterField,filterGroup,filterCheck,filterErrorandfilterClear, styled byGridStyle. Like the menu, the form is drawn inside the grid's scroll box, so a grid too short to hold it clips it. - Pinned columns stick to their edge with
position: stickyand carrydata-pinned="start"or"end"; the pinned column next to the scrolling ones also carriesdata-pinned-edge, header and cells, whereGridStyledraws the divider they pass under. The focused cell carriesdata-focused="true".
Styling
Every element above is a Slot. A Style may paint anything, but the geometry
the window is worked out from is the view's: a Style that sets a cell's
width, position, insetInlineStart or boxSizing, a row's height, or
the root's overflow is refused with slot "cell" protects style property.
Cells are border-box, so padding stays inside the width the window assumed.