Roving-grid board
A dense grid of state cells that is one tab stop with arrow-key navigation, where each state differs in fill, border weight, and border style at once — and clicking selects but never writes.
Reach for it when building
- episode or chapter trackers
- habit and streak grids
- seat or slot pickers
- batch item status boards
- calendar day selectors
<div class="rgb-wrap">
<div class="rgb-grid" role="listbox" aria-label="Chapters" aria-orientation="horizontal" aria-describedby="rgb-hint"></div>
<div class="rgb-legend">
<span><i class="rgb-swatch rgb-sw-done" aria-hidden="true"></i> read</span>
<span><i class="rgb-swatch rgb-sw-next" aria-hidden="true"></i> next up</span>
<span><i class="rgb-swatch" aria-hidden="true"></i> unread</span>
<span><i class="rgb-swatch rgb-sw-unavailable" aria-hidden="true"></i> unreleased</span>
</div>
<div class="rgb-panel">
<span class="rgb-msg">Chapter 8 — next</span>
<button type="button" class="rgb-commit">Read up to here</button>
</div>
<p class="rgb-hint" id="rgb-hint">One tab stop: arrow keys move, Home and End jump. Selecting never changes progress.</p>
<div class="rgb-status" role="status"></div>
</div>Colors come from shared theme tokens — --surface, --ink, --border, --accent and friends — so this CSS carries no palette
of its own. Use Runnable file to copy the tokens along with it.
.rgb-wrap { max-width: 460px; }
.rgb-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.rgb-cell {
width: 44px;
height: 44px;
display: grid;
place-items: center;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--surface);
font-family: var(--sans);
font-size: 1rem;
color: var(--ink);
cursor: pointer;
padding: 0;
font-variant-numeric: tabular-nums;
}
.rgb-cell:hover { border-color: var(--dim); }
/* Each state moves fill, border weight, and border style together, so no
state is distinguished by color alone. */
.rgb-cell[data-state='done'] {
background: var(--accent);
color: var(--accent-ink);
border-color: transparent;
font-weight: 700;
}
.rgb-cell[data-state='next'] {
border: 2px solid var(--accent);
font-weight: 700;
}
.rgb-cell[data-state='unavailable'] {
border-style: dashed;
border-color: var(--dim);
color: var(--dim);
cursor: default;
}
/* A ground-colored gap, then a solid ring: the ring stays visible around a
filled cell, where a ring touching the fill would vanish into it. */
.rgb-cell[data-selected='true'] {
box-shadow:
0 0 0 2px var(--ground),
0 0 0 4px var(--accent);
}
/* Focus sits outside the selection ring instead of covering it. */
.rgb-cell:focus-visible { outline-offset: 5px; position: relative; z-index: 1; }
.rgb-legend {
display: flex;
flex-wrap: wrap;
gap: 1rem;
font-size: 0.9375rem;
color: var(--dim);
margin-top: 0.75rem;
}
.rgb-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
/* Legend swatches reuse the exact state treatments at small scale. */
.rgb-swatch {
width: 17px;
height: 17px;
border-radius: 4px;
border: 1px solid var(--border);
background: var(--surface);
display: inline-block;
}
.rgb-sw-done { background: var(--accent); border-color: transparent; }
.rgb-sw-next { border: 2px solid var(--accent); }
.rgb-sw-unavailable { border-style: dashed; border-color: var(--dim); }
.rgb-panel {
display: flex;
align-items: center;
gap: 1rem;
flex-wrap: wrap;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--surface);
padding: 0.7rem 1rem;
margin-top: 0.9rem;
}
.rgb-commit {
font-family: var(--sans);
font-size: 0.9375rem;
font-weight: 600;
padding: 0.4rem 0.8rem;
border-radius: 6px;
border: 1px solid var(--dim);
background: var(--surface);
color: var(--ink);
cursor: pointer;
}
.rgb-commit:hover { background: var(--surface-2); }
.rgb-commit[aria-disabled='true'] {
border-style: dashed;
color: var(--dim);
cursor: not-allowed;
}
.rgb-commit[aria-disabled='true']:hover { background: var(--surface); }
.rgb-hint { margin: 0.75rem 0 0; color: var(--dim); }
.rgb-status {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}var TOTAL = 15;
var doneUpTo = 7;
var releasedUpTo = 12;
var selected = 8;
var grid = document.querySelector('.rgb-grid');
var message = document.querySelector('.rgb-msg');
var commit = document.querySelector('.rgb-commit');
var statusLine = document.querySelector('.rgb-status');
// Cells per row, measured, because the grid wraps to whatever width it gets.
function columnCount() {
var cells = grid.children;
var count = 0;
while (count < cells.length && cells[count].offsetTop === cells[0].offsetTop) count++;
return count;
}
function stateOf(index) {
if (index > releasedUpTo) return 'unavailable';
if (index <= doneUpTo) return 'done';
if (index === doneUpTo + 1) return 'next';
return 'unread';
}
function label(state) {
return { done: 'read', next: 'next', unread: 'unread', unavailable: 'unreleased' }[state];
}
function render() {
grid.innerHTML = '';
for (var index = 1; index <= TOTAL; index++) {
(function (cellIndex) {
var cell = document.createElement('button');
cell.type = 'button';
cell.className = 'rgb-cell';
cell.textContent = String(cellIndex);
var state = stateOf(cellIndex);
cell.dataset.state = state;
cell.dataset.selected = String(cellIndex === selected);
// Roving tabindex: the whole grid is one tab stop.
cell.tabIndex = cellIndex === selected ? 0 : -1;
cell.setAttribute('role', 'option');
cell.setAttribute('aria-selected', String(cellIndex === selected));
cell.setAttribute('aria-label', 'Chapter ' + cellIndex + ', ' + label(state));
cell.addEventListener('click', function () { select(cellIndex, true); });
cell.addEventListener('keydown', function (event) {
var target = null;
if (event.key === 'ArrowRight') target = Math.min(TOTAL, cellIndex + 1);
if (event.key === 'ArrowLeft') target = Math.max(1, cellIndex - 1);
// Up and down move a whole row and stay put at the top and bottom edges.
if (event.key === 'ArrowDown') target = cellIndex + columnCount() <= TOTAL ? cellIndex + columnCount() : cellIndex;
if (event.key === 'ArrowUp') target = cellIndex - columnCount() >= 1 ? cellIndex - columnCount() : cellIndex;
if (event.key === 'Home') target = 1;
if (event.key === 'End') target = TOTAL;
if (target !== null) {
event.preventDefault();
select(target, true);
}
});
grid.appendChild(cell);
})(index);
}
message.textContent = 'Chapter ' + selected + ' \u2014 ' + label(stateOf(selected));
// aria-disabled rather than disabled: the button stays focusable and can say why.
if (stateOf(selected) === 'unavailable') commit.setAttribute('aria-disabled', 'true');
else commit.removeAttribute('aria-disabled');
}
function select(index, focus) {
selected = index;
render();
if (focus) grid.children[index - 1].focus();
}
commit.addEventListener('click', function () {
if (stateOf(selected) === 'unavailable') {
statusLine.textContent = 'Chapter ' + selected + ' is not released yet, so progress did not change.';
return;
}
var previous = doneUpTo;
doneUpTo = selected;
render();
// Moving progress back un-reads chapters, and the announcement has to say so.
if (selected < previous) {
statusLine.textContent = 'Progress moved back to chapter ' + selected + '. ' +
(selected + 1 === previous ? 'Chapter ' + previous + ' is' : 'Chapters ' + (selected + 1) + ' to ' + previous + ' are') +
' unread again.';
} else if (selected === previous) {
statusLine.textContent = 'Already read up to chapter ' + selected + '; nothing changed.';
} else {
statusLine.textContent = selected === 1 ? 'Chapter 1 marked read.' : 'Chapters 1 to ' + selected + ' marked read.';
}
});
render();Paste this into an agent to rebuild the pattern from scratch.
Build a dense grid of small state cells — chapters read, days kept, slots taken — with a keyboard model and a state system that both survive real data.
States: each cell is a 44px button whose state moves three properties together — fill, border weight, and border style — so no state is distinguishable by color alone. Done: solid accent fill, contrast text, transparent border, bold. Next-up: 2px accent border on the neutral surface, bold. Unread: the plain 1px border. Unavailable (not yet released): dashed border in the dim text color (a dashed line in the faint border color is invisible) and dimmed text. Ship a legend whose swatches reuse the identical state rules at 17px — a legend styled separately drifts the first time someone touches the CSS.
Keyboard: the whole grid is one tab stop, implemented with a roving tabindex. Only the selected cell has `tabIndex = 0`; every other cell is `-1`. ArrowLeft/ArrowRight move selection by one, ArrowUp/ArrowDown move by one row (measure the cells per row from layout, because the grid wraps to its container, and stay put at the top and bottom edges), Home and End jump to the ends, and each move both re-renders selection and calls `.focus()` on the new cell, with `preventDefault()` so the page doesn't scroll. Without this, a 40-cell grid costs 40 tab presses to cross. Pressing Enter or Space on the focused cell fires the button's native `click` event, which runs the same selection path — return focus the same way there, or a keyboard user who activates a cell loses their place the instant it re-renders.
Writes are decoupled from selection: clicking or arrowing onto a cell only selects it and updates a panel beneath ("Chapter 8 — next"); the actual mutation happens through an explicit button in that panel ("Read up to here"). A mis-click can never rewrite progress. When the selected cell is unavailable the button takes `aria-disabled="true"` and a dimmed, dashed look, but stays focusable; pressing it changes nothing and says why. Every press of the button reports its result in a `role="status"` line ("Chapters 1 to 10 marked read."), because the cells refilling is a change a screen reader user cannot see. Pressing it on an already-read chapter moves progress back, and the line must say which chapters became unread again ("Progress moved back to chapter 3. Chapters 4 to 7 are unread again.") rather than claim a plain "marked read"; arrowing does not use that line, since the focused cell's own label is already read out. Print the keyboard model as one short hint under the board and point the grid's `aria-describedby` at it. The initial selection is the next-up cell — the one the person most likely came to act on — not cell 1 and not nothing.
Selection is shown with a box-shadow ring rather than a border change, so selecting never shifts layout: a 2px gap in the page background color, then a 2px solid accent ring. The gap is what keeps the ring visible around a done cell, whose fill is the same accent. Push the focus outline out past that ring so keyboard focus and selection are both visible. Give cells `role="option"`, `aria-selected`, and an `aria-label` combining position and state, and the container `role="listbox"` with a label.
Every color comes from theme custom properties, and every state must stay distinguishable in both light and dark themes.