Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
make Dashboard Arrange move and resize handles work from the keyboard (#7263)
[._.]/ Adam Eivy6aa93fdc9033
diff --git a/client/src/components/KeyboardHelp.jsx b/client/src/components/KeyboardHelp.jsxindex ab6c5fcbe1..47db189f43 100644--- a/client/src/components/KeyboardHelp.jsx+++ b/client/src/components/KeyboardHelp.jsx@@ -23,6 +23,15 @@ const SHORTCUT_SECTIONS = [{ keys: ['Esc'], description: 'Close palette' },],},+ {+ title: 'Dashboard Arrange (when a move or resize handle is focused)',+ shortcuts: [+ { keys: ['Enter', 'Space'], description: 'Grab the widget — press again to place it' },+ { keys: ['←', '→'], description: 'Move a column, or resize by a column' },+ { keys: ['↑', '↓'], description: 'Move up or down the order, or resize by a row' },+ { keys: ['Esc'], description: 'Put the widget back where it was' },+ ],+ },{title: 'OpenWorld',shortcuts: [diff --git a/client/src/components/dashboard/AGENTS.md b/client/src/components/dashboard/AGENTS.mdindex 2828723eb1..3abb1ac836 100644--- a/client/src/components/dashboard/AGENTS.md+++ b/client/src/components/dashboard/AGENTS.md@@ -8,6 +8,8 @@ Dashboard widgets are registered in `widgetRegistry.jsx` — each entry has `{ i**Height is measured, not declared.** `h` is NOT the rendered height. A cell measures its widget's natural height with a `ResizeObserver` and `packVertically` positions everything in pixels — each cell floats up to just below the nearest already-placed cell that shares a column. That's what stops an 80px card from reserving a 400px slot and leaving a band of dead whitespace across the row. `h` survives as the pre-measurement fallback (first paint) and as what an older client — which knows nothing about `fixedH` — reads out of a saved layout, so every drag commit refreshes it from the measurement via `withMeasuredHeights`. A cell whose height the user actually dragged carries `fixedH: true` and keeps `h` exactly, clipping content the way the whole grid used to; the ⌃⌄ handle (edit mode, pinned cells only) hands the height back to the content. `defaultH` in the registry is likewise only a first-paint ballpark.+**The desktop handles are keyboard gestures too (#7263).** Move and resize are grab toggles, not pointer-only affordances: Enter/Space lifts the cell, the arrows step it, Enter/Space drops it and Escape puts it back — deliberately the same state machine dnd-kit gives the mobile reorder handle, so both feel like one feature. There is **one** placement path, not two: `beginGesture` freezes the same snapshot for either input, `stepGhost` snaps in the same units the pointer drag rounds to (a column; a rank or a row), `finishGesture` applies the same `applyGhost` and the same `fixedH` rule, and the preview a keyboard step draws IS the commit. Only where the next ghost comes from differs — a pixel delta, or one arrow press. The single divergence is deliberate: a horizontal *move* step leaves `order` alone, where the drag re-derives it from `rankAtPixel` every frame, so ↑/↓ owns the sequence outright and no press has a second effect the user can't see coming. The grid's `role="status"` region narrates each step (the drag doesn't narrate — it's already visible to whoever is doing it), and `aria-pressed` carries grabbed/idle. **A new handle wired with `onPointerDown` alone is a WCAG 2.1.1 failure**, not a nice-to-have: it announces an action through its `aria-label` and then does nothing, which reads as broken rather than unavailable. `DashboardGrid.test.jsx` fails on any `<DragHandle>` in the source that takes `onPointerDown` without `onKeyDown`.+**Mobile editing.** Free-form move/resize is desktop-only (a phone has no room for positional editing), but *reordering* works on mobile: edit mode swaps the two grid handles for a single reorder handle. The 1-D sort goes through **`@dnd-kit/sortable`** — the same `PointerSensor` + `KeyboardSensor` + `verticalListSortingStrategy` pairing as `cos/tabs/TasksTab.jsx` and `universeBuilder/InfluenceChipsInput.jsx` — which is what supplies touch, keyboard (space to lift, arrows to move), multi-pointer safety, screen-reader announcements and edge auto-scroll. **Do not hand-roll a pointer gesture for this**; the free-form 2-D drag stays hand-rolled only because arbitrary grid placement is not what a sortable list does. Use `dndTransformToCss` from `client/src/lib/dndTransform.js` in the style object, never `@dnd-kit/utilities`.On drop, `onDragEnd` re-flows the whole grid through `reflowToOrder` so its reading order matches the new stack order, preserving each widget's `w`/`h`. That means a mobile reorder re-packs the desktop layout into row-flow — the only coherent way to express a one-dimensional edit as column placement, and the edit-mode hint says so. `synthesizeGrid` is built on the same helper. The handle keeps `touch-action: none`; without it the browser claims the pointer stream for scrolling and the gesture never starts.diff --git a/client/src/components/dashboard/DashboardGrid.jsx b/client/src/components/dashboard/DashboardGrid.jsxindex 3d5949a2ef..0ae1e8cca1 100644--- a/client/src/components/dashboard/DashboardGrid.jsx+++ b/client/src/components/dashboard/DashboardGrid.jsx@@ -55,6 +55,16 @@ import { dndTransformToCss } from '../../lib/dndTransform';// regardless of which element the pointer crosses — the listener lives on// `window` for the duration of the gesture.//+// KEYBOARD RUNS THE SAME GESTURE (#7263). Both handles are also grab toggles:+// Enter/Space lifts the cell, the arrows step the ghost, Enter/Space drops it+// and Escape puts it back. There is deliberately no second placement path —+// `beginGesture` freezes the identical snapshot the pointer drag freezes,+// `stepGhost` snaps in the same units the pointer rounds to, and the commit+// goes through the same `applyGhost`. What differs is only where the next+// ghost comes from: a pixel delta, or one arrow press. That is what keeps the+// promise above (one vertical coordinate) intact — a keyboard step never+// introduces a coordinate space the pointer path doesn't already have.+//// Below MOBILE_BREAKPOINT_PX the grid collapses to a single column, so x/w// have nowhere to go — but ORDER still does. There, edit mode swaps the two// grid handles for one reorder handle that sorts the stack via dnd-kit (the@@ -100,6 +110,26 @@ const MOBILE_BREAKPOINT_PX = 640;// whose column ties would then re-rank itself on a zero-distance click.const SAME_ROW_PX = ROW_HEIGHT_PX / 2;+// One arrow press, in the units the gesture already snaps to: a column on the+// horizontal axis, and on the vertical axis one sequence rank (move) or one+// row step (resize). Signs follow the pointer drag rather than the visual+// metaphor — dragging DOWN grows a cell and pushes it later in the sequence,+// so ArrowDown does both too.+const ARROW_STEPS = {+ ArrowLeft: { axis: 'x', delta: -1 },+ ArrowRight: { axis: 'x', delta: 1 },+ ArrowUp: { axis: 'y', delta: -1 },+ ArrowDown: { axis: 'y', delta: 1 },+};++// Keys that lift and drop a handle. ' ' is what every browser still in scope+// reports; 'Spacebar' is legacy IE/Edge and costs one array entry.+const GRAB_KEYS = ['Enter', ' ', 'Spacebar'];++function clamp(value, min, max) {+ return Math.max(min, Math.min(max, value));+}+function getColWidth(containerWidth) {return (containerWidth - GAP_PX * (GRID_COLS - 1)) / GRID_COLS;}@@ -246,6 +276,52 @@ function applyGhost(baseline, kind, ghost, pin) {: insertAtOrder(swapped, ghost.id, ghost.order);}+// Advance a keyboard gesture's ghost by one arrow press. The clamps are the+// SAME ones the pointer path applies to its rounded pixel delta — a move stays+// inside the 12 columns and inside the sequence, a resize keeps MIN_W/MIN_H+// and cannot run off the right edge — so the two gestures can never reach a+// placement the other couldn't.+//+// `count` is how many cells are in the sequence; the last rank is count-1+// because a move re-INSERTS the cell rather than adding one.+//+// A step that would leave the grid comes back as the same values, so the+// caller can compare placements and skip both the re-render and the+// announcement rather than narrating a press that did nothing.+//+// The one deliberate divergence from the drag: a horizontal move step leaves+// `order` alone, where the pointer path re-derives it from `rankAtPixel` on+// every frame (which is what makes dragging a card sideways past its row+// neighbour swap the two). Here ↑/↓ owns the sequence outright, so "change+// columns, keep my place in the reading order" is expressible — and a press+// never has a second, unasked-for effect the user can't see coming.+export function stepGhost(kind, ghost, key, count) {+ const step = ARROW_STEPS[key];+ if (!step) return ghost;+ if (kind === 'move') {+ return step.axis === 'x'+ ? { ...ghost, x: clamp(ghost.x + step.delta, 0, GRID_COLS - ghost.w) }+ : { ...ghost, order: clamp(ghost.order + step.delta, 0, Math.max(0, count - 1)) };+ }+ return step.axis === 'x'+ ? { ...ghost, w: clamp(ghost.w + step.delta, MIN_W, GRID_COLS - ghost.x) }+ // No ceiling, same as the drag: the pack owns vertical space, so a tall+ // cell costs page height and nothing else.+ : { ...ghost, h: Math.max(MIN_H, ghost.h + step.delta) };+}++// What a screen reader hears. The registry label, not the raw id, and 1-based+// numbers because they're read aloud to a human counting columns.+function widgetLabel(item) {+ return WIDGETS_BY_ID[item.id]?.label ?? item.id;+}++function describePlacement(kind, ghost, count) {+ return kind === 'move'+ ? `column ${ghost.x + 1} of ${GRID_COLS}, position ${ghost.order + 1} of ${count}`+ : `${ghost.w} of ${GRID_COLS} columns wide, ${ghost.h} rows tall`;+}+// Everything that differs between the three handles, on one row each. `kind`// already discriminates them, so icon/size/placement hang off it rather than// travelling as separate props.@@ -275,16 +351,34 @@ const HANDLE_KINDS = {// their own onPointerDown instead. `touchAction: 'none'` is what makes any of// them work under a finger — without it the browser claims the pointer stream// for scrolling.-function DragHandle({ kind, item, onPointerDown, onClick, handleProps }) {+//+// The two grid handles additionally pass `onKeyDown`/`grabbed`, which is what+// makes them toggle buttons rather than pointer-only affordances: `aria-pressed`+// is the idle/grabbed state, and the grid's live region narrates each step.+// `grabbed` stays undefined on the handles that are plain buttons (auto-fit) or+// already announce themselves through dnd-kit (reorder), so those keep their+// unpressed semantics.+function DragHandle({ kind, item, onPointerDown, onClick, onKeyDown, onBlur, grabbed, handleProps }) {const { label, Icon, size, className } = HANDLE_KINDS[kind];+ // The two states SWAP their surface/border/ink rather than layering a+ // grabbed set on top of the idle one: Tailwind emits utilities in its own+ // order, so `border-port-accent` and `border-port-border` in one class+ // string are decided by the stylesheet, not by which came last here — the+ // same trap `client/src/AGENTS.md` records for `inline-flex`.+ const stateClass = grabbed+ ? 'bg-port-accent/20 border-port-accent text-white ring-1 ring-port-accent'+ : 'bg-port-bg/90 border-port-border text-gray-300 hover:text-white hover:border-port-accent';return (<buttontype="button"onPointerDown={onPointerDown}onClick={onClick}+ onKeyDown={onKeyDown}+ onBlur={onBlur}+ aria-pressed={grabbed}// The registry label, not the raw id — this is read aloud.- aria-label={`${label} ${WIDGETS_BY_ID[item.id]?.label ?? item.id}`}- className={`absolute z-20 bg-port-bg/90 border border-port-border rounded text-gray-300 hover:text-white hover:border-port-accent ${className}`}+ aria-label={`${label} ${widgetLabel(item)}`}+ className={`absolute z-20 border rounded ${stateClass} ${className}`}style={{ touchAction: 'none' }}{...handleProps}>@@ -383,7 +477,8 @@ export function readingOrderIds(grid) {// `renderItem` for all ~12 widgets to move one card.const GridCell = memo(function GridCell({item, isMobile, editable, sortable, left, top, width, height, autoHeight, isGridDragging,- suppressTransition, onStartGridDrag, onClearFixedHeight, onMeasure, renderItem,+ suppressTransition, onStartGridDrag, onHandleKeyDown, onHandleBlur, grabbedKind,+ onClearFixedHeight, onMeasure, renderItem,}) {const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({id: item.id,@@ -468,8 +563,22 @@ const GridCell = memo(function GridCell({</div>{editable && !isMobile && (<>- <DragHandle kind="move" item={item} onPointerDown={(e) => onStartGridDrag(e, item, 'move')} />- <DragHandle kind="resize" item={item} onPointerDown={(e) => onStartGridDrag(e, item, 'resize')} />+ <DragHandle+ kind="move"+ item={item}+ onPointerDown={(e) => onStartGridDrag(e, item, 'move')}+ onKeyDown={(e) => onHandleKeyDown(e, item, 'move')}+ onBlur={() => onHandleBlur(item, 'move')}+ grabbed={grabbedKind === 'move'}+ />+ <DragHandle+ kind="resize"+ item={item}+ onPointerDown={(e) => onStartGridDrag(e, item, 'resize')}+ onKeyDown={(e) => onHandleKeyDown(e, item, 'resize')}+ onBlur={() => onHandleBlur(item, 'resize')}+ grabbed={grabbedKind === 'resize'}+ />{item.fixedH && (<DragHandle kind="auto-height" item={item} onClick={() => onClearFixedHeight(item)} />)}@@ -500,6 +609,10 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeCconst [drag, setDrag] = useState(null);// Measured natural heights, px, keyed by widget id.const [heights, setHeights] = useState({});+ // What the grid's live region currently says. Only the keyboard gesture+ // writes it: a pointer drag is already visible to the person doing it, and+ // narrating 60 snaps a second would flood the speech queue.+ const [announcement, setAnnouncement] = useState('');const onMeasure = useCallback((id, px) => {setHeights((prev) => (prev[id] === px ? prev : { ...prev, [id]: px }));@@ -556,25 +669,19 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeC[ordered, heights]);- const startDrag = useCallback((e, item, kind) => {- if (!editable || isMobile) return;- // Prevent text selection mid-drag. preventDefault on the handle's- // pointerdown is enough because the listener lives on window and we- // never let the pointer leave the gesture.- e.preventDefault();- e.stopPropagation();- // Freeze the pack's output for the gesture: the ghost has to start exactly- // where the card is DRAWN (grabbing the resize handle on an auto-height- // cell would otherwise snap it to a stale row count before the pointer- // moved), and the rank math has to compare against positions the preview- // isn't simultaneously shifting.+ // Freeze everything a gesture reasons about, whatever started it. The ghost+ // has to begin exactly where the card is DRAWN (grabbing the resize handle+ // on an auto-height cell would otherwise snap it to a stale row count before+ // the first step), and the rank math has to compare against positions the+ // preview isn't simultaneously shifting.+ const beginGesture = useCallback((item, kind) => {const baseRects = rectsRef.current;const baseline = withMeasuredHeights(items, baseRects);const found = baseline.find((it) => it.id === item.id) ?? item;- // A resize gesture's floor applies to where the drag STARTS too. Without- // it, a cell measuring under MIN_H rows (a widget rendering little or- // nothing) has its height "changed" by the clamp alone — so a purely- // horizontal drag would silently pin it.+ // A resize gesture's floor applies to where it STARTS too. Without it, a+ // cell measuring under MIN_H rows (a widget rendering little or nothing)+ // has its height "changed" by the clamp alone — so a purely horizontal+ // drag would silently pin it.//// A move's start is expressed as the rank the cell ALREADY reads at, not// its stored `order`. The two can differ: the pack places in sequence, but@@ -586,19 +693,111 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeCconst startItem = kind === 'resize'? { ...found, h: Math.max(MIN_H, found.h) }: { ...found, order: rankAtPixel(baseline, baseRects, item.id, startTop, found.x) };- dragRef.current = {- id: item.id,- kind,- startPointer: { x: e.clientX, y: e.clientY },- startTop,- startItem,- ghost: { ...startItem },- };- setDrag({ kind, baseline, baseRects, ghost: { ...startItem } });- }, [editable, isMobile, items]);+ return { id: item.id, kind, baseline, baseRects, startTop, startItem, ghost: { ...startItem } };+ }, [items]);++ // Fold the gesture in `dragRef` back into the layout, then clear it. Shared+ // by the pointer drop and the keyboard commit so "what a gesture writes" has+ // exactly one definition; returns whether anything was actually written.+ const finishGesture = useCallback((commit) => {+ const gesture = dragRef.current;+ dragRef.current = null;+ setDrag(null);+ if (!gesture || !commit) return false;+ // Skip the write entirely when nothing actually changed — avoids a 200 OK+ // on every accidental click of the drag handle.+ if (samePlacement(gesture.startItem, gesture.ghost)) return false;+ // A resize that actually changed the HEIGHT is the user declaring one:+ // pin it. A width-only resize (or a move) leaves the cell auto-sized.+ const pins = gesture.kind === 'resize' && gesture.ghost.h !== gesture.startItem.h;+ onChange(applyGhost(gesture.baseline, gesture.kind, gesture.ghost, pins));+ return true;+ }, [onChange]);++ const startDrag = useCallback((e, item, kind) => {+ if (!editable || isMobile) return;+ // Prevent text selection mid-drag. preventDefault on the handle's+ // pointerdown is enough because the listener lives on window and we+ // never let the pointer leave the gesture.+ e.preventDefault();+ e.stopPropagation();+ const gesture = beginGesture(item, kind);+ dragRef.current = { ...gesture, startPointer: { x: e.clientX, y: e.clientY } };+ setDrag({ kind, baseline: gesture.baseline, baseRects: gesture.baseRects, ghost: { ...gesture.startItem } });+ }, [editable, isMobile, beginGesture]);++ // Enter/Space lifts a handle, the arrows step it, Enter/Space drops it and+ // Escape puts it back — the same state machine dnd-kit gives the mobile+ // reorder handle, so the two gestures feel like one feature.+ const handleKeyDown = useCallback((e, item, kind) => {+ if (!editable || isMobile) return;+ // A chord belongs to the browser or the app, not to this handle — ⌘←+ // navigates back, ⌥↑ jumps a paragraph. Only the bare key is a gesture.+ if (e.metaKey || e.ctrlKey || e.altKey) return;+ const gesture = dragRef.current;+ const grabbed = Boolean(gesture?.keyboard) && gesture.id === item.id && gesture.kind === kind;+ const count = items.length;++ if (GRAB_KEYS.includes(e.key)) {+ // Suppress the button's own activation: Enter/Space on a <button> would+ // otherwise fire a click straight after this, and the grab toggle would+ // cancel itself.+ e.preventDefault();+ e.stopPropagation();+ if (!grabbed) {+ const next = beginGesture(item, kind);+ dragRef.current = { ...next, keyboard: true };+ setDrag({ kind, keyboard: true, baseline: next.baseline, baseRects: next.baseRects, ghost: { ...next.startItem } });+ setAnnouncement(`${widgetLabel(item)} grabbed. ${describePlacement(kind, next.startItem, count)}. Use the arrow keys, then Enter to place or Escape to cancel.`);+ return;+ }+ const placed = finishGesture(true);+ setAnnouncement(`${widgetLabel(item)} ${kind === 'resize' ? 'resized' : 'placed'}. ${placed ? describePlacement(kind, gesture.ghost, count) : 'Unchanged'}.`);+ return;+ }++ if (!grabbed) return;++ if (e.key === 'Escape') {+ // Nothing was written, so dropping the gesture IS the restore — and the+ // stop keeps Escape from also leaving Arrange mode behind our back.+ e.preventDefault();+ e.stopPropagation();+ finishGesture(false);+ setAnnouncement(`${widgetLabel(item)} returned to its original position.`);+ return;+ }++ if (!ARROW_STEPS[e.key]) return;+ // Claim the arrow before the page scrolls under the grabbed cell.+ e.preventDefault();+ e.stopPropagation();+ const next = stepGhost(kind, gesture.ghost, e.key, count);+ // A step clamped at an edge changes nothing — say nothing and re-render+ // nothing rather than repeating the last position back at the user.+ if (samePlacement(gesture.ghost, next)) return;+ gesture.ghost = next;+ setDrag((prev) => (prev ? { ...prev, ghost: { ...next } } : prev));+ setAnnouncement(`${describePlacement(kind, next, count)}.`);+ }, [editable, isMobile, items, beginGesture, finishGesture]);++ // Tabbing (or clicking) away from a grabbed handle abandons the gesture+ // rather than leaving a ghost the user can no longer steer. Scoped to the+ // handle that actually holds the grab, so starting a POINTER drag on a+ // sibling handle — whose pointerdown lands before this blur — isn't undone+ // by it.+ const handleBlur = useCallback((item, kind) => {+ const gesture = dragRef.current;+ if (!gesture?.keyboard || gesture.id !== item.id || gesture.kind !== kind) return;+ finishGesture(false);+ setAnnouncement(`${widgetLabel(item)} returned to its original position.`);+ }, [finishGesture]);useEffect(() => {- if (!drag) return undefined;+ // A keyboard grab drives itself from the handle's own keydown — installing+ // the window pointer listeners for it would let a click anywhere on the+ // page drop the cell.+ if (!drag || drag.keyboard) return undefined;const colWidth = getColWidth(containerWidth);// Both are fixed for the life of the gesture, and this effect re-installs// exactly when one starts — so capturing them here can't go stale, and the@@ -645,17 +844,7 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeCconst finish = (commit) => {if (raf) { cancelAnimationFrame(raf); raf = 0; }- const gesture = dragRef.current;- dragRef.current = null;- setDrag(null);- if (!gesture || !commit) return;- // Skip the write entirely when nothing actually changed — avoids a- // 200 OK on every accidental click on the drag handle.- if (samePlacement(gesture.startItem, gesture.ghost)) return;- // A resize that actually changed the HEIGHT is the user declaring one:- // pin it. A width-only resize (or a move) leaves the cell auto-sized.- const pins = kind === 'resize' && gesture.ghost.h !== gesture.startItem.h;- onChange(applyGhost(baseline, kind, gesture.ghost, pins));+ finishGesture(commit);};const onPointerUp = () => finish(true);@@ -673,10 +862,12 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeCwindow.removeEventListener('pointercancel', onPointerCancel);if (raf) cancelAnimationFrame(raf);};- // The active/idle key re-installs the listeners only when the gesture+ // The mode key re-installs the listeners only when a POINTER gesture// starts/ends, never on a snap — pointermove writes dragRef.current// directly, and the `kind`/`baseline` captured above are gesture-constant.- }, [drag ? 'active' : 'idle', onChange, containerWidth]);+ // A keyboard grab is its own mode, so switching between the two re-runs+ // this instead of leaving the wrong listeners bound.+ }, [drag ? (drag.keyboard ? 'keyboard' : 'pointer') : 'idle', finishGesture, containerWidth]);// A short activation distance keeps a tap on the handle from registering as// a drag; the keyboard sensor is what makes the handle usable without one.@@ -752,6 +943,9 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeCisGridDragging={!isMobile && dragged}suppressTransition={Boolean(drag) || !settled}onStartGridDrag={startDrag}+ onHandleKeyDown={handleKeyDown}+ onHandleBlur={handleBlur}+ grabbedKind={drag?.keyboard && drag.ghost.id === item.id ? drag.kind : null}onClearFixedHeight={clearFixedHeight}onMeasure={onMeasure}renderItem={renderItem}@@ -768,6 +962,13 @@ export default function DashboardGrid({ items, editable, onChange, onLayoutModeCstyle={{ ...columnRect(drag.ghost, colWidth), ...rects.get(drag.ghost.id) }}/>)}++ {/* Where a keyboard gesture narrates itself. The pointer drag is+ already visible to whoever is doing it; an arrow step is not, so+ this is the only feedback that says a press landed. `polite` so+ a fast run of arrow presses queues behind the current utterance+ instead of cutting it off. */}+ <div role="status" aria-live="polite" className="sr-only">{announcement}</div></div></SortableContext></DndContext>diff --git a/client/src/components/dashboard/DashboardGrid.test.jsx b/client/src/components/dashboard/DashboardGrid.test.jsxindex 0af98cb3e7..58aa3165ff 100644--- a/client/src/components/dashboard/DashboardGrid.test.jsx+++ b/client/src/components/dashboard/DashboardGrid.test.jsx@@ -1,4 +1,7 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';+import { readFileSync } from 'node:fs';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';import { fireEvent, render, screen } from '@testing-library/react';// Stub @dnd-kit/core's DndContext so drag-end can be fired imperatively. The@@ -43,7 +46,7 @@ vi.mock('@dnd-kit/sortable', async () => {const DashboardGrid = (await import('./DashboardGrid.jsx')).default;const {reflowToOrder, synthesizeGrid, reconcileGrid, readingOrderIds,- packVertically, itemHeightPx, rowsToPx, pxToRows,+ packVertically, itemHeightPx, rowsToPx, pxToRows, stepGhost,} = await import('./DashboardGrid.jsx');// jsdom has no ResizeObserver, and useContainerWidth (which decides mobile vs@@ -508,6 +511,218 @@ describe('DashboardGrid move re-sequences', () => {});});+// The keyboard path has to produce the SAME commits as the pointer path —+// that is the whole design constraint (#7263). These assert on the committed+// grid array, not on internal ghost state, so a second placement path+// sneaking in would show up as a differently-shaped commit.+describe('DashboardGrid keyboard arrange', () => {+ beforeEach(() => { mockWidth = 1200; });++ const grab = (label) => {+ const handle = screen.getByLabelText(label);+ handle.focus();+ fireEvent.keyDown(handle, { key: 'Enter' });+ return handle;+ };+ const press = (handle, key) => fireEvent.keyDown(handle, { key });++ // THREE is full-width, so its cells have nowhere to go horizontally — the+ // column clamp would swallow every sideways press.+ const NARROW = [+ { id: 'a', x: 0, w: 4, order: 0, h: 2 },+ { id: 'b', x: 0, w: 4, order: 1, h: 2 },+ { id: 'c', x: 0, w: 4, order: 2, h: 2 },+ ];++ it('moves a widget across columns and down the order, then commits on Enter', () => {+ const onChange = renderGrid(NARROW);+ const handle = grab('Move a');+ press(handle, 'ArrowRight');+ press(handle, 'ArrowRight');+ press(handle, 'ArrowDown');+ expect(onChange).not.toHaveBeenCalled();++ press(handle, 'Enter');+ const next = onChange.mock.calls[0][0];+ expect(next.map((it) => it.id)).toEqual(['b', 'a', 'c']);+ expect(next.map((it) => it.order)).toEqual([0, 1, 2]);+ expect(next.find((it) => it.id === 'a').x).toBe(2);+ // A move never declares a height, exactly like the drag.+ for (const it of next) expect(it.fixedH).toBeUndefined();+ });++ it('resizes by columns and rows, pinning the height it committed', () => {+ const onChange = renderGrid([{ id: 'a', x: 0, w: 12, order: 0, h: 2 }]);+ const handle = grab('Resize a');+ press(handle, 'ArrowLeft');+ press(handle, 'ArrowLeft');+ press(handle, 'ArrowDown');+ press(handle, 'Enter');++ const resized = onChange.mock.calls[0][0].find((it) => it.id === 'a');+ expect(resized.w).toBe(10);+ expect(resized.h).toBe(3);+ expect(resized.fixedH).toBe(true);+ });++ it('leaves a width-only keyboard resize auto-sized', () => {+ const onChange = renderGrid([{ id: 'a', x: 0, w: 12, order: 0, h: 2 }]);+ const handle = grab('Resize a');+ press(handle, 'ArrowLeft');+ press(handle, 'Enter');+ expect(onChange.mock.calls[0][0].find((it) => it.id === 'a').fixedH).toBeUndefined();+ });++ it('writes nothing when the grab is cancelled with Escape', () => {+ const onChange = renderGrid();+ const handle = grab('Move a');+ press(handle, 'ArrowRight');+ press(handle, 'ArrowDown');+ press(handle, 'Escape');+ expect(onChange).not.toHaveBeenCalled();+ expect(handle).toHaveAttribute('aria-pressed', 'false');++ // …and the next Enter starts a fresh grab rather than committing the+ // abandoned one.+ press(handle, 'Enter');+ expect(handle).toHaveAttribute('aria-pressed', 'true');+ expect(onChange).not.toHaveBeenCalled();+ });++ it('abandons the grab when focus leaves the handle', () => {+ const onChange = renderGrid();+ const handle = grab('Move a');+ press(handle, 'ArrowDown');+ fireEvent.blur(handle);+ expect(handle).toHaveAttribute('aria-pressed', 'false');+ expect(onChange).not.toHaveBeenCalled();+ });++ it('writes nothing when a grab is committed without stepping', () => {+ const onChange = renderGrid();+ const handle = grab('Move b');+ press(handle, 'Enter');+ expect(onChange).not.toHaveBeenCalled();+ });++ it('reports grabbed state and narrates each step in the live region', () => {+ renderGrid(NARROW);+ const status = document.querySelector('[role="status"]');+ expect(status).toHaveAttribute('aria-live', 'polite');++ const handle = grab('Move a');+ expect(handle).toHaveAttribute('aria-pressed', 'true');+ expect(status.textContent).toContain('grabbed');+ expect(status.textContent).toContain('column 1 of 12');++ press(handle, 'ArrowRight');+ expect(status.textContent).toContain('column 2 of 12');++ press(handle, 'Enter');+ expect(handle).toHaveAttribute('aria-pressed', 'false');+ expect(status.textContent).toContain('placed');+ });++ // Only the two grid handles are grab toggles; the reorder handle announces+ // itself through dnd-kit and auto-fit is a plain button, so neither should+ // claim pressed semantics.+ it('marks only the move and resize handles as toggles', () => {+ renderGrid([{ id: 'a', x: 0, w: 12, order: 0, h: 3, fixedH: true }]);+ expect(screen.getByLabelText('Move a')).toHaveAttribute('aria-pressed', 'false');+ expect(screen.getByLabelText('Resize a')).toHaveAttribute('aria-pressed', 'false');+ expect(screen.getByLabelText('Auto-fit height a')).not.toHaveAttribute('aria-pressed');+ });++ // A grabbed cell owns the arrows and Enter/Escape; letting them through+ // scrolls the page under the ghost, or drops out of Arrange mode entirely.+ it('claims the keys it handles while grabbed, and only those', () => {+ renderGrid();+ const handle = screen.getByLabelText('Move a');+ handle.focus();+ // Not grabbed: an arrow is somebody else's key.+ expect(fireEvent.keyDown(handle, { key: 'ArrowRight' })).toBe(true);++ fireEvent.keyDown(handle, { key: 'Enter' });+ expect(fireEvent.keyDown(handle, { key: 'ArrowRight' })).toBe(false);+ expect(fireEvent.keyDown(handle, { key: 'Escape' })).toBe(false);+ // An unrelated key stays available to the page in both states.+ expect(fireEvent.keyDown(handle, { key: 'Tab' })).toBe(true);+ });++ // ⌘← is browser navigation, ⌥↑ is a text jump — a chord is never a step.+ it('leaves modifier chords to the browser', () => {+ const onChange = renderGrid(NARROW);+ const handle = grab('Move a');+ expect(fireEvent.keyDown(handle, { key: 'ArrowRight', metaKey: true })).toBe(true);+ expect(fireEvent.keyDown(handle, { key: 'ArrowDown', altKey: true })).toBe(true);+ press(handle, 'Enter');+ expect(onChange).not.toHaveBeenCalled();+ });++ // The regression this file exists to prevent: a handle wired with+ // onPointerDown alone announces an action and then does nothing from the+ // keyboard.+ it('leaves no handle with a pointer-only activation path', () => {+ renderGrid();+ for (const label of ['Move a', 'Resize a']) {+ const handle = screen.getByLabelText(label);+ handle.focus();+ fireEvent.keyDown(handle, { key: ' ' });+ expect(handle, `${label} ignored Space`).toHaveAttribute('aria-pressed', 'true');+ fireEvent.keyDown(handle, { key: 'Escape' });+ }+ });++ // …and the same guard for a handle that doesn't exist yet. The rendered+ // check above can only speak for the handles a fixture happens to produce;+ // a third pointer-driven handle added later would pass it by simply not+ // being there, which is exactly how the first two got shipped inert.+ it('gives every pointer-driven DragHandle in the source a keyboard path', () => {+ const source = readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'DashboardGrid.jsx'), 'utf8');+ // Slice each element at its own closing bracket so a neighbour's props+ // can never satisfy this on its behalf.+ const offenders = source.split('<DragHandle').slice(1)+ .map((rest) => rest.slice(0, rest.indexOf('/>')))+ .filter((props) => props.includes('onPointerDown') && !props.includes('onKeyDown'));+ expect(offenders, `DragHandle wired for pointer only:\n${offenders.join('\n---\n')}`).toEqual([]);+ });+});++// The clamps are what keep the keyboard from reaching a placement the drag+// could not, so they get pinned directly — an integration test can only show+// that SOME edge held, not which bound produced it.+describe('stepGhost', () => {+ const move = { id: 'a', x: 0, w: 4, h: 3, order: 0 };++ it('steps a move by one column and one rank', () => {+ expect(stepGhost('move', move, 'ArrowRight', 3).x).toBe(1);+ expect(stepGhost('move', move, 'ArrowDown', 3).order).toBe(1);+ });++ it('holds a move inside the grid and inside the sequence', () => {+ expect(stepGhost('move', move, 'ArrowLeft', 3).x).toBe(0);+ expect(stepGhost('move', move, 'ArrowUp', 3).order).toBe(0);+ expect(stepGhost('move', { ...move, x: 8 }, 'ArrowRight', 3).x).toBe(8);+ expect(stepGhost('move', { ...move, order: 2 }, 'ArrowDown', 3).order).toBe(2);+ });++ it('keeps a resize above the minimums and inside the right edge', () => {+ expect(stepGhost('resize', { ...move, w: 2 }, 'ArrowLeft', 1).w).toBe(2);+ expect(stepGhost('resize', { ...move, h: 2 }, 'ArrowUp', 1).h).toBe(2);+ expect(stepGhost('resize', { ...move, x: 8, w: 4 }, 'ArrowRight', 1).w).toBe(4);+ });++ // Horizontal is columns-only by design: ↑/↓ owns the sequence, so a sideways+ // step never re-ranks the cell behind the user's back.+ it('leaves the sequence alone on a horizontal move step', () => {+ expect(stepGhost('move', { ...move, order: 1 }, 'ArrowRight', 3).order).toBe(1);+ });++ it('ignores a key that is not an arrow', () => {+ expect(stepGhost('move', move, 'Enter', 3)).toBe(move);+ });+});+describe('DashboardGrid scroll target', () => {beforeEach(() => { mockWidth = 1200; });diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsxindex 81bc70b9e6..efb055731e 100644--- a/client/src/pages/Dashboard.jsx+++ b/client/src/pages/Dashboard.jsx@@ -538,9 +538,10 @@ export default function Dashboard() {) : (<>Drag the <Move size={12} className="inline mx-0.5" /> handle to move widgets, or- the <span className="inline-block px-1">↘</span> handle to resize. Widgets size- themselves to their content and float up into the space above — dragging a- widget's height pins it, and the{' '}+ the <span className="inline-block px-1">↘</span> handle to resize — or focus+ either one and press space, then the arrow keys, then enter (escape cancels).+ Widgets size themselves to their content and float up into the space above —+ setting a widget's height pins it, and the{' '}<ChevronsDownUp size={12} className="inline mx-0.5" /> handle hands it back.</>)}