An open source design system that's fully customizable and agent ready
TypeScript
fix(ResizeHandle): arrows move between snap points (#7514)
Cindy Zhanga05bcd24b599
diff --git a/.changeset/resize-handle-snap-arrows.md b/.changeset/resize-handle-snap-arrows.mdnew file mode 100644index 0000000000..cc6e8d094f--- /dev/null+++ b/.changeset/resize-handle-snap-arrows.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `ResizeHandle`: with snap points set, an arrow key moves the pane to the adjacent snap point in its direction (Shift moves two), a point beyond the bounds counting as that bound — a 10px step used to snap straight back to the point it started on. With snap points, a shrink arrow at the lowest point no longer collapses a collapsible pane; Enter, double-click and dragging still do.++@cixzhangdiff --git a/packages/core/src/Resizable/Resizable.spec.md b/packages/core/src/Resizable/Resizable.spec.mdindex 7b3363b90b..04abed4450 100644--- a/packages/core/src/Resizable/Resizable.spec.md+++ b/packages/core/src/Resizable/Resizable.spec.md@@ -160,20 +160,22 @@ values used by hook state and painted geometry.ArrowRight and ArrowDown move the divider toward the end of its axis andArrowLeft and ArrowUp toward the start, the inline arrows following thereading direction under RTL, with Shift for a larger step, so the pane grows- or shrinks by the side of the Handle it sits on; Home moves to the minimum- size and End to the maximum; Enter collapses a collapsible pane and restores- it, and the arrow that grows a collapsed pane opens it one step above its- minimum, or at its `collapsedSize` when that is larger (the shrinking arrow- leaves it collapsed). An unbounded Handle reports a measured stand-in as- `aria-valuemax`: the window's extent along its axis when no container is- supplied, or its container's content box while a percentage bound observes it,- never below its current size or, while collapsed, its minimum. Implementation- gaps under `spec:AST-020/FR15`: the Handle names the pane it resizes with- `aria-controls` only when its caller passes one (SideNav does); an unbounded- Handle in a container that no percentage bound observes carries no- `aria-valuemax`, because measuring that container would add an observer to a- region whose bounds are all in pixels (Performance and resources); and End- does not move an unbounded Handle.+ or shrinks by the side of the Handle it sits on; with snap points set, an+ arrow moves to the adjacent snap point, a point beyond `minSize` or `maxSize`+ counting as that bound (Shift, two); Home moves to the minimum size and End to+ the maximum; Enter collapses a collapsible pane and restores it, and the arrow+ that grows a collapsed pane opens it one step above its minimum, or at its+ `collapsedSize` when that is larger (with snap points, at the snap point+ nearest that size; the shrinking arrow leaves it collapsed). An unbounded+ Handle reports a measured stand-in as `aria-valuemax`: the window's extent+ along its axis when no container is supplied, or its container's content box+ while a percentage bound observes it, never below its current size or, while+ collapsed, its minimum. Implementation gaps under `spec:AST-020/FR15`: the+ Handle names the pane it resizes with `aria-controls` only when its caller+ passes one (SideNav does); an unbounded Handle in a container that no+ percentage bound observes carries no `aria-valuemax`, because measuring that+ container would add an observer to a region whose bounds are all in pixels+ (Performance and resources); and End does not move an unbounded Handle.## Design relationships@@ -221,16 +223,16 @@ not emit the documented target state.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |-| FR1 | `ResizeHandle.test.tsx` plus source inspection | Default, custom, collapsed, disabled, both axes | Handle and Grab zone regressions fail focused tests; custom Grip replacement currently relies on source review. | `audit:Resizable/anatomy` |-| AR1 | `ResizeHandle.test.tsx` ("makes the separator focusable", "exposes the region size and bounds via ARIA", "grows the panel by a step on ArrowRight", "shrinks the panel by a step on ArrowLeft", "uses the large step when Shift is held", "jumps to the minimum on Home", "jumps to the maximum on End", "collapses on Enter when the region is collapsible", "inverts the pointer delta under RTL so dragging resizes intuitively", "restores the previous size, not the minimum, when Enter reopens a collapsed pane", "reopens on Enter even when the minimum size sits below the collapse threshold", "reports the window basis as aria-valuemax when no maximum is configured; End leaves an unbounded region alone", "reports the container basis as aria-valuemax while a percentage bound already observes it", "never reports aria-valuemax below aria-valuemin while collapsed in a small window", "reports no aria-valuemax for an unbounded pixel-only region in a container, which stays unobserved", "a grow arrow opens a collapsed pane one step above its minimum; the shrink arrow leaves it collapsed", "a grow arrow opens a collapsed pane at its collapsedSize when the minimum sits below it", "a grow arrow opens a collapsed pane in the reversed layout and under RTL too", "in a reversed layout, ArrowLeft opens a collapsed pane and ArrowRight leaves it collapsed", "under RTL, ArrowLeft opens a collapsed pane and ArrowRight leaves it collapsed", "a grow arrow opens a hand-built collapsed region one step above its minimum") and `shippedDirections.test.ts`; `SideNav.test.tsx` ("names the nav it resizes with aria-controls (APG window splitter)"); RTL keyboard mirroring, and the disabled state under the Window Splitter accessibility contract (`internal/a11y-spec`, pending) | Inline and block axes; LTR and RTL; collapsed; disabled | The Handle loses its role, name, orientation or value properties; an arrow, Home, End or Enter stops moving the divider or moves it against the reading direction | `audit:Resizable/accessibility` |-| FR2 | Source inspection and `themingTargets.test.ts` | Handle, Grip pill, and Grab zone | Removing a target or documenting an unshipped Grab zone target fails evidence or inventory. | `audit:Resizable/theming` |-| FR3 | `ResizeHandle.test.tsx` and `useResizable.test.ts` | Pointer, keyboard, snap, collapse, persistence | Moving resize ownership or changing current transformations fails focused behavior coverage. | `audit:Resizable/behavior` |-| FR4 | Source and public metadata comparison | Horizontal and vertical Handle | No current test detects that documented `direction` is absent from runtime target-state reflection. | `audit:Resizable/theming` |-| FR5 | Hook/utils tests, typecheck, and Chromium | Canonical floor/ceiling/default; invalid XOR shape; SSR/hydration; basis changes; numeric `containerRef` parity | Wrong resolution, rescaling defaults, stale clamps, observer leaks, extra numeric renders/ref reads, or state/paint/storage/ARIA divergence fails. | `audit:Resizable/behavior` |-| FR6 | Hook type/runtime and codemod tests | Removed alias type errors; single/multi-region inline migrations; numeric pixel bounds | A removed alias still type-checks, or migration changes its numeric meaning. | `audit:Resizable/behavior` |-| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and two current targets | Missing, extra, prefixed, stale, or multiply assigned mappings fail repository validation. | `audit:Resizable/theming` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |+| FR1 | `ResizeHandle.test.tsx` plus source inspection | Default, custom, collapsed, disabled, both axes | Handle and Grab zone regressions fail focused tests; custom Grip replacement currently relies on source review. | `audit:Resizable/anatomy` |+| AR1 | `ResizeHandle.test.tsx` ("makes the separator focusable", "exposes the region size and bounds via ARIA", "grows the panel by a step on ArrowRight", "shrinks the panel by a step on ArrowLeft", "uses the large step when Shift is held", "jumps to the minimum on Home", "jumps to the maximum on End", "collapses on Enter when the region is collapsible", "inverts the pointer delta under RTL so dragging resizes intuitively", "restores the previous size, not the minimum, when Enter reopens a collapsed pane", "reopens on Enter even when the minimum size sits below the collapse threshold", "reports the window basis as aria-valuemax when no maximum is configured; End leaves an unbounded region alone", "reports the container basis as aria-valuemax while a percentage bound already observes it", "never reports aria-valuemax below aria-valuemin while collapsed in a small window", "reports no aria-valuemax for an unbounded pixel-only region in a container, which stays unobserved", "a grow arrow opens a collapsed pane one step above its minimum; the shrink arrow leaves it collapsed", "a grow arrow opens a collapsed pane at its collapsedSize when the minimum sits below it", "a grow arrow opens a collapsed pane in the reversed layout and under RTL too", "in a reversed layout, ArrowLeft opens a collapsed pane and ArrowRight leaves it collapsed", "under RTL, ArrowLeft opens a collapsed pane and ArrowRight leaves it collapsed", "a grow arrow opens a hand-built collapsed region one step above its minimum", "with snap points, an arrow moves to the adjacent point in its direction and Shift moves two, clamped to the ends", "with snap points past the bounds, a point beyond maxSize or minSize counts as that bound", "with snap points, the arrows follow the reversed layout and the reading direction", "with snap points in a reversed layout, ArrowLeft moves to the next point and ArrowRight to the previous", "with snap points, the grow arrow opens a collapsed pane at the snap point nearest one step above its minimum") and `shippedDirections.test.ts`; `SideNav.test.tsx` ("names the nav it resizes with aria-controls (APG window splitter)"); RTL keyboard mirroring, and the disabled state under the Window Splitter accessibility contract (`internal/a11y-spec`, pending) | Inline and block axes; LTR and RTL; collapsed; disabled | The Handle loses its role, name, orientation or value properties; an arrow, Home, End or Enter stops moving the divider or moves it against the reading direction | `audit:Resizable/accessibility` |+| FR2 | Source inspection and `themingTargets.test.ts` | Handle, Grip pill, and Grab zone | Removing a target or documenting an unshipped Grab zone target fails evidence or inventory. | `audit:Resizable/theming` |+| FR3 | `ResizeHandle.test.tsx` and `useResizable.test.ts` | Pointer, keyboard, snap, collapse, persistence | Moving resize ownership or changing current transformations fails focused behavior coverage. | `audit:Resizable/behavior` |+| FR4 | Source and public metadata comparison | Horizontal and vertical Handle | No current test detects that documented `direction` is absent from runtime target-state reflection. | `audit:Resizable/theming` |+| FR5 | Hook/utils tests, typecheck, and Chromium | Canonical floor/ceiling/default; invalid XOR shape; SSR/hydration; basis changes; numeric `containerRef` parity | Wrong resolution, rescaling defaults, stale clamps, observer leaks, extra numeric renders/ref reads, or state/paint/storage/ARIA divergence fails. | `audit:Resizable/behavior` |+| FR6 | Hook type/runtime and codemod tests | Removed alias type errors; single/multi-region inline migrations; numeric pixel bounds | A removed alias still type-checks, or migration changes its numeric meaning. | `audit:Resizable/behavior` |+| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and two current targets | Missing, extra, prefixed, stale, or multiply assigned mappings fail repository validation. | `audit:Resizable/theming` |Current tests exercise Handle and Grab zone structure and behavior but do notrender `children` to prove that custom content replaces Grip pill. That branch isdiff --git a/packages/core/src/Resizable/ResizeHandle.test.tsx b/packages/core/src/Resizable/ResizeHandle.test.tsxindex eaf33c4ab3..4496c339d5 100644--- a/packages/core/src/Resizable/ResizeHandle.test.tsx+++ b/packages/core/src/Resizable/ResizeHandle.test.tsx@@ -592,6 +592,142 @@ describe('ResizeHandle', () => {}});+ it('with snap points, an arrow moves to the adjacent point in its direction and Shift moves two, clamped to the ends', () => {+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 100,+ maxSize: 400,+ snaps: [100, 200, 300, 400],+ }}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ // A 10px step would snap straight back to 200; the arrow reaches the+ // next point instead.+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ fireEvent.keyDown(separator, {key: 'ArrowLeft'});+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ fireEvent.keyDown(separator, {key: 'ArrowRight', shiftKey: true});+ expect(separator).toHaveAttribute('aria-valuenow', '400');+ // Already at the last point: the grow arrow changes nothing.+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).toHaveAttribute('aria-valuenow', '400');+ // Shift past the first point clamps to it.+ fireEvent.keyDown(separator, {key: 'ArrowLeft', shiftKey: true});+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ fireEvent.keyDown(separator, {key: 'ArrowLeft', shiftKey: true});+ expect(separator).toHaveAttribute('aria-valuenow', '100');+ fireEvent.keyDown(separator, {key: 'ArrowLeft'});+ expect(separator).toHaveAttribute('aria-valuenow', '100');+ });++ it('with snap points past the bounds, a point beyond maxSize or minSize counts as that bound', () => {+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 100,+ maxSize: 400,+ snaps: [50, 100, 200, 300, 450],+ }}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ fireEvent.keyDown(separator, {key: 'End'});+ expect(separator).toHaveAttribute('aria-valuenow', '400');+ fireEvent.keyDown(separator, {key: 'ArrowLeft'});+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ // The 450 point counts as the 400 bound.+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).toHaveAttribute('aria-valuenow', '400');+ fireEvent.keyDown(separator, {key: 'Home'});+ expect(separator).toHaveAttribute('aria-valuenow', '100');+ // The 50 point counts as the 100 bound: nothing below it.+ fireEvent.keyDown(separator, {key: 'ArrowLeft'});+ expect(separator).toHaveAttribute('aria-valuenow', '100');+ });++ it('with snap points, the arrows follow the reversed layout and the reading direction', () => {+ const rtl = vi+ .spyOn(window, 'getComputedStyle')+ .mockImplementation(+ () => ({direction: 'rtl'}) as unknown as CSSStyleDeclaration,+ );+ try {+ // Reversed under RTL: the two inversions cancel, so ArrowRight grows.+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 100,+ maxSize: 400,+ snaps: [100, 200, 300, 400],+ }}+ handleProps={{isReversed: true}}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ fireEvent.keyDown(separator, {key: 'ArrowLeft'});+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ } finally {+ rtl.mockRestore();+ }+ });++ it('with snap points in a reversed layout, ArrowLeft moves to the next point and ArrowRight to the previous', () => {+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 100,+ maxSize: 400,+ snaps: [100, 200, 300, 400],+ }}+ handleProps={{isReversed: true}}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ fireEvent.keyDown(separator, {key: 'ArrowLeft'});+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ });++ it('with snap points, the grow arrow opens a collapsed pane at the snap point nearest one step above its minimum', () => {+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 100,+ maxSize: 400,+ collapsible: true,+ snaps: [100, 200, 300, 400],+ }}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ fireEvent.keyDown(separator, {key: 'Enter'});+ expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');+ // min + step is 110; the region can rest only on a point, so it opens+ // on the nearest one (100).+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).not.toHaveAttribute('aria-valuetext');+ expect(separator).toHaveAttribute('aria-valuenow', '100');+ // From there the arrows move between points.+ fireEvent.keyDown(separator, {key: 'ArrowRight'});+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ });+it('a grow arrow opens a hand-built collapsed region one step above its minimum', () => {const props: ResizableProps = {...makeResizable(),diff --git a/packages/core/src/Resizable/ResizeHandle.tsx b/packages/core/src/Resizable/ResizeHandle.tsxindex 25ae240d3b..248e97df20 100644--- a/packages/core/src/Resizable/ResizeHandle.tsx+++ b/packages/core/src/Resizable/ResizeHandle.tsx@@ -364,6 +364,35 @@ export interface ResizeHandleProps extends Omit<children?: ReactNode;}+/**+ * The snap point `count` points away from the region's current size in+ * `direction` (+1 grows, -1 shrinks). A point beyond `minSize` or `maxSize`+ * counts as that bound; the nearest end point serves when fewer remain, and+ * the current size when it is already there.+ */+function adjacentSnapPoint(+ resizable: ResizableProps,+ direction: 1 | -1,+ count: number,+): number {+ const points = [+ ...new Set(+ resizable._snaps.map(p =>+ Math.min(resizable._maxSizePx, Math.max(resizable._minSizePx, p)),+ ),+ ),+ ].sort((a, b) => a - b);+ const size = resizable._size;+ const ahead =+ direction > 0+ ? points.filter(p => p > size)+ : points.filter(p => p < size).reverse();+ if (ahead.length === 0) {+ return size;+ }+ return ahead[Math.min(count, ahead.length) - 1];+}+/*** Collapse an open pane, or restore a collapsed one to the size it had before* it collapsed (APG window splitter: Enter "restores the splitter to its@@ -594,6 +623,22 @@ export function ResizeHandle({}break;}+ if (resizable._snaps.length > 0) {+ // With snap points the region can rest only on a point, so a+ // pixel step would snap straight back; the arrow moves to the+ // adjacent point in its direction instead (Shift, two points),+ // staying within the bounds.+ resizable._onResizeStart();+ resizable._onResizeMove(+ adjacentSnapPoint(+ resizable,+ grows(e.key) ? 1 : -1,+ e.shiftKey ? 2 : 1,+ ) - resizable._size,+ );+ resizable._onResizeEnd();+ break;+ }const direction =e.key === 'ArrowRight' || e.key === 'ArrowDown' ? 1 : -1;resizable._onResizeStart();diff --git a/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.known-failures.ts b/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.known-failures.tsindex d3c55d9ff2..f6f3135389 100644--- a/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.known-failures.ts+++ b/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.known-failures.ts@@ -23,19 +23,6 @@ export const RESIZE_HANDLE_KNOWN_FAILURES: ReadonlyArray<KnownFailure> = [reason:'A recorded gap with a reason the record owns (Performance and resources: atomic pixel paths add no observer); it closes only with a record decision, not a fix.',},- {- expectation: 'windowsplitter.keys.arrows-move',- binding: 'ResizeHandle',- state: 'bare-snapped',- evidenceLayer: 'real-browser',- failureEquals: 'ArrowRight (grow) left aria-valuenow at 200, not 210',- standardsReference:- 'APG Window Splitter keyboard interaction — the arrow keys move the splitter; Astryx component:Resizable AR1.',- userImpact:- 'A keyboard user on a region with snap points presses an arrow and nothing happens: a 10px step snaps back to the point it started on, so only a pointer drag reaches the next point.',- reason:- 'This test-only binding records the gap; moving to the adjacent snap point on an arrow is a component decision for its own spec-backed patch.',- },{expectation: 'windowsplitter.separator.controls-pane',binding: 'ResizeHandle',diff --git a/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.states.ts b/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.states.tsindex 1164e875f5..7b33f6e845 100644--- a/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.states.ts+++ b/packages/core/src/Resizable/__tests__/ResizeHandle.a11y.states.ts@@ -145,11 +145,12 @@ export const RESIZE_HANDLE_BINDING_STATES = [{id: 'bare-snapped',summary:- 'a bare ResizeHandle whose region sets snap points [100, 200, 300, 400]: it can rest only on a snap point',+ 'a bare ResizeHandle whose region sets snap points [100, 200, 300, 400]: an arrow moves to the adjacent point',storyId: story('bare-snapped'),component: 'ResizeHandle',label: 'Resize details pane',- facts: facts(),+ // One arrow moves to the adjacent point: 100px apart here.+ facts: facts({step: 100}),snaps: [100, 200, 300, 400],},{