Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(ResizeHandle): an unbounded region reports its measured basis as aria-valuemax (#7481)

Cindy Zhangf11eb6d09505
diff --git a/.changeset/resize-handle-valuemax.md b/.changeset/resize-handle-valuemax.md
new file mode 100644
index 0000000000..a8f362dee2
--- /dev/null
+++ b/.changeset/resize-handle-valuemax.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `ResizeHandle`: a separator whose region sets no `maxSize` now reports an `aria-valuemax` — a measured extent standing in for the missing maximum (the window's extent on the region's axis, or the container's content box while a percentage bound observes it), never below the current size or, while collapsed, the minimum. Pixel-only regions inside a container still report no maximum (measuring one would add an observer). `ResizableProps` is unchanged; End still moves only to a configured maximum.
+
+@cixzhang
diff --git a/packages/core/src/Resizable/ResizeHandle.test.tsx b/packages/core/src/Resizable/ResizeHandle.test.tsx
index c935ab9454..9d9a4e5e5a 100644
--- a/packages/core/src/Resizable/ResizeHandle.test.tsx
+++ b/packages/core/src/Resizable/ResizeHandle.test.tsx
@@ -15,8 +15,11 @@
* which is bound to the region's `_size`.
*/
+import {useRef} from 'react';
import {describe, it, expect, vi} from 'vitest';
-import {render, screen, fireEvent, act} from '@testing-library/react';
+import {render, screen, fireEvent, act, waitFor} from '@testing-library/react';
+import {hydrateRoot} from 'react-dom/client';
+import {renderToString} from 'react-dom/server';
import {ResizeHandle} from './ResizeHandle';
import type {ResizeHandleProps} from './ResizeHandle';
import {useResizable} from './useResizable';
@@ -130,6 +133,192 @@ describe('ResizeHandle', () => {
expect(separator).toHaveAttribute('aria-valuenow', '100');
});
+ it('reports the window basis as aria-valuemax when no maximum is configured; End leaves an unbounded region alone', () => {
+ const previous = window.innerWidth;
+ window.innerWidth = 1000;
+ try {
+ render(<Harness config={{defaultSize: 200, minSize: 100}} />);
+ const separator = getSeparator();
+ // ARIA needs a maximum on a separator with a value: the basis the hook
+ // resolves against stands in for an unbounded one.
+ expect(separator).toHaveAttribute('aria-valuemax', '1000');
+ // End still moves only to a configured maximum: the stand-in says how
+ // far the pane could reach, not where the handle may safely go
+ // (component:Resizable records the End gap).
+ act(() => separator.focus());
+ fireEvent.keyDown(separator, {key: 'End'});
+ expect(separator).toHaveAttribute('aria-valuenow', '200');
+ } finally {
+ window.innerWidth = previous;
+ }
+ });
+
+ it('server-renders an unbounded handle with no maximum and reports the window extent after hydration, with no hydration error', async () => {
+ const previous = window.innerWidth;
+ window.innerWidth = 1000;
+ const probe = <Harness config={{defaultSize: 200, minSize: 100}} />;
+ const serverHTML = renderToString(probe);
+ // The server has no window: no aria-valuemax in the markup.
+ expect(serverHTML).not.toContain('aria-valuemax');
+ const container = document.createElement('div');
+ container.innerHTML = serverHTML;
+ document.body.appendChild(container);
+ const consoleError = vi
+ .spyOn(console, 'error')
+ .mockImplementation(() => {});
+ const recoverableErrors: unknown[] = [];
+ let root: ReturnType<typeof hydrateRoot>;
+ try {
+ await act(async () => {
+ root = hydrateRoot(container, probe, {
+ onRecoverableError: error => recoverableErrors.push(error),
+ });
+ });
+ // The first client render reads the window through the store and
+ // reports it; a render-time window read would mismatch the server
+ // markup (or, read only once, leave the attribute missing).
+ await waitFor(() =>
+ expect(container.querySelector('[role="separator"]')).toHaveAttribute(
+ 'aria-valuemax',
+ '1000',
+ ),
+ );
+ expect(recoverableErrors).toEqual([]);
+ expect(
+ consoleError.mock.calls.filter(call =>
+ String(call[0] ?? '')
+ .toLowerCase()
+ .includes('hydrat'),
+ ),
+ ).toEqual([]);
+ } finally {
+ await act(async () => root!.unmount());
+ consoleError.mockRestore();
+ container.remove();
+ window.innerWidth = previous;
+ }
+ });
+
+ it('never reports a maximum below the current size, and End does not shrink the region', () => {
+ const previous = window.innerWidth;
+ window.innerWidth = 500;
+ try {
+ // A default (or saved, or pre-resize) size larger than the window.
+ render(<Harness config={{defaultSize: 800, minSize: 100}} />);
+ const separator = getSeparator();
+ expect(separator).toHaveAttribute('aria-valuenow', '800');
+ expect(separator).toHaveAttribute('aria-valuemax', '800');
+ act(() => separator.focus());
+ fireEvent.keyDown(separator, {key: 'End'});
+ expect(separator).toHaveAttribute('aria-valuenow', '800');
+ } finally {
+ window.innerWidth = previous;
+ }
+ });
+
+ it('never reports aria-valuemax below aria-valuemin while collapsed in a small window', () => {
+ const previous = window.innerWidth;
+ window.innerWidth = 375;
+ try {
+ render(
+ <Harness
+ config={{defaultSize: 500, minSize: 400, collapsible: true}}
+ />,
+ );
+ const separator = getSeparator();
+ act(() => separator.focus());
+ fireEvent.keyDown(separator, {key: 'Enter'});
+ expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');
+ expect(separator).toHaveAttribute('aria-valuemin', '400');
+ expect(
+ Number(separator.getAttribute('aria-valuemax')),
+ ).toBeGreaterThanOrEqual(400);
+ } finally {
+ window.innerWidth = previous;
+ }
+ });
+
+ it('reports the window height, not the width, for an unbounded vertical region', () => {
+ const previousWidth = window.innerWidth;
+ const previousHeight = window.innerHeight;
+ window.innerWidth = 1000;
+ window.innerHeight = 700;
+ try {
+ render(
+ <Harness
+ config={{defaultSize: 200, minSize: 100, direction: 'vertical'}}
+ handleProps={{direction: 'vertical'}}
+ />,
+ );
+ const separator = getSeparator();
+ expect(separator).toHaveAttribute('aria-valuemax', '700');
+ } finally {
+ window.innerWidth = previousWidth;
+ window.innerHeight = previousHeight;
+ }
+ });
+
+ it('reports the container basis as aria-valuemax while a percentage bound already observes it', () => {
+ function ContainerHarness() {
+ const containerRef = useRef<HTMLDivElement>(null);
+ const region = useResizable({
+ defaultSize: 200,
+ minSize: '10%',
+ containerRef,
+ });
+ return (
+ <div ref={containerRef}>
+ <ResizeHandle resizable={region.props} label="Resize" />
+ </div>
+ );
+ }
+ // jsdom has no ResizeObserver; a stub lets the hook subscribe, and the
+ // content box is measured through clientWidth minus padding.
+ class StubResizeObserver {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ }
+ vi.stubGlobal('ResizeObserver', StubResizeObserver);
+ const clientWidth = vi
+ .spyOn(HTMLElement.prototype, 'clientWidth', 'get')
+ .mockReturnValue(640);
+ const computedStyle = vi.spyOn(window, 'getComputedStyle').mockReturnValue({
+ paddingTop: '0px',
+ paddingBottom: '0px',
+ paddingLeft: '0px',
+ paddingRight: '0px',
+ } as unknown as CSSStyleDeclaration);
+ try {
+ render(<ContainerHarness />);
+ expect(getSeparator()).toHaveAttribute('aria-valuemax', '640');
+ } finally {
+ clientWidth.mockRestore();
+ computedStyle.mockRestore();
+ vi.unstubAllGlobals();
+ }
+ });
+
+ it('reports no aria-valuemax for an unbounded pixel-only region in a container, which stays unobserved', () => {
+ function ContainerHarness() {
+ const containerRef = useRef<HTMLDivElement>(null);
+ const region = useResizable({
+ defaultSize: 200,
+ minSize: 100,
+ containerRef,
+ });
+ return (
+ <div ref={containerRef}>
+ <ResizeHandle resizable={region.props} label="Resize" />
+ </div>
+ );
+ }
+ render(<ContainerHarness />);
+ // component:Resizable Performance: atomic pixel paths add no observer, so
+ // the hook never measures this container and reports no stand-in.
+ expect(getSeparator()).not.toHaveAttribute('aria-valuemax');
+ });
+
it('jumps to the maximum on End', () => {
render(<Harness />);
const separator = getSeparator();
diff --git a/packages/core/src/Resizable/ResizeHandle.tsx b/packages/core/src/Resizable/ResizeHandle.tsx
index 548f7c9522..5fcc8cf662 100644
--- a/packages/core/src/Resizable/ResizeHandle.tsx
+++ b/packages/core/src/Resizable/ResizeHandle.tsx
@@ -46,7 +46,11 @@ import {
} from '../theme/tokens.stylex';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
import {mergeProps, rtlStyles} from '../utils';
-import {getCollapseControls, type ResizableProps} from './useResizable';
+import {
+ getCollapseControls,
+ getEffectiveMaxPx,
+ type ResizableProps,
+} from './useResizable';
import {themeProps} from '../utils/themeProps';
import {useTranslator} from '../i18n';
@@ -580,6 +584,9 @@ export function ResizeHandle({
}
case 'End': {
e.preventDefault();
+ // Only a configured maximum is the region's own limit; the reported
+ // stand-in for an unbounded region is where the pane *could* reach,
+ // not where End may safely move it (a recorded gap).
if (resizable._maxSizePx !== Infinity) {
resizable._onResizeStart();
resizable._onResizeMove(resizable._maxSizePx - resizable._size);
@@ -638,9 +645,16 @@ export function ResizeHandle({
: resizable._size
: undefined;
const ariaValueMin = resizable ? resizable._minSizePx : undefined;
+ // A separator with a value needs a maximum (WAI-ARIA, APG window splitter).
+ // Unbounded regions report the basis they can fill; a hand-built props
+ // object without it reports only a configured maximum.
+ const effectiveMax = resizable
+ ? (getEffectiveMaxPx(resizable) ??
+ (resizable._maxSizePx !== Infinity ? resizable._maxSizePx : undefined))
+ : undefined;
const ariaValueMax =
- resizable && resizable._maxSizePx !== Infinity
- ? resizable._maxSizePx
+ effectiveMax != null && Number.isFinite(effectiveMax)
+ ? effectiveMax
: undefined;
const ariaValueText =
resizable && isCollapsed ? t('@astryx.resizable.collapsed') : undefined;
diff --git a/packages/core/src/Resizable/useResizable.ts b/packages/core/src/Resizable/useResizable.ts
index c61c694a71..7c011937b2 100644
--- a/packages/core/src/Resizable/useResizable.ts
+++ b/packages/core/src/Resizable/useResizable.ts
@@ -303,6 +303,9 @@ function persistState(key: string, state: PersistedResizableState): void {
/** The released compatibility basis when there is no window to measure. */
const SERVER_BASIS = 1200;
+
+/** A store that never changes on its own; the snapshot is re-read on render. */
+const noopSubscribe = () => () => {};
const DEFAULT_SIZE_FALLBACK = 250;
const RESIZABLE_SIZE_GUIDANCE =
'Use a non-negative number of pixels, an exact "Npx" string, an exact ' +
@@ -699,6 +702,23 @@ function useSingleResizable(config: UseResizableSingleConfig): ResizableRegion {
() => SERVER_BASIS,
);
+ // The window's extent along the hook's axis, for the REPORTED maximum of an
+ // unbounded region (never for clamping). Read through the same store shape
+ // so a server-rendered handle hydrates with no maximum and gains the real
+ // one on the first client render, instead of a hydration mismatch. It takes
+ // no resize subscription: an unbounded pixel region observes nothing
+ // (component:Resizable Performance and resources).
+ const windowExtent = useSyncExternalStore(
+ noopSubscribe,
+ () =>
+ typeof window === 'undefined'
+ ? null
+ : direction === 'vertical'
+ ? window.innerHeight
+ : window.innerWidth,
+ () => null,
+ );
+
// With a container, its content box is the basis; without one, the released
// viewport basis. Before a supplied container has been measured — the first
// render, the server, and any moment it is display:none or detached — the
@@ -1026,6 +1046,29 @@ function useSingleResizable(config: UseResizableSingleConfig): ResizableRegion {
// percentage bound stays pinned to the container size at grab time.
const onResizeCancel = releaseGestureBasis;
+ // The maximum a handle REPORTS (End uses only a configured maximum). A
+ // configured maximum wins. Otherwise a measured extent stands in — the
+ // container's content box while a percentage bound already observes it, or
+ // the window's extent along the axis — and never drops below the current size, so
+ // `aria-valuenow` can never exceed `aria-valuemax` (a saved, default, or
+ // pre-resize size may already be larger than the window). An unobserved
+ // container reports nothing: measuring it would add an observer to an
+ // atomic pixel path.
+ const measuredBasisForMax = hasContainer
+ ? hasPositiveMeasurement && observeContainerBasis
+ ? containerBasis
+ : null
+ : windowExtent;
+ // Never below the announced value either: a collapsed pane announces the
+ // resolved minimum as its value, so the stand-in floors there as well, and
+ // `aria-valuemax` can never fall under `aria-valuemin`.
+ const effectiveMaxPx =
+ resolvedMax !== Infinity
+ ? resolvedMax
+ : measuredBasisForMax == null
+ ? undefined
+ : Math.max(measuredBasisForMax, isCollapsed ? resolvedMin : size);
+
const props: ResizableProps = {
_size: isCollapsed ? 0 : size,
_isCollapsed: isCollapsed,
@@ -1042,6 +1085,15 @@ function useSingleResizable(config: UseResizableSingleConfig): ResizableRegion {
_isResizableProps: true,
};
collapseControls.set(props, {collapse, expand});
+ // Without a configured maximum the basis stands in — only when it is a
+ // real measurement (an observed container, or the window), never the
+ // temporary 1200px placeholder (component:Resizable Performance: atomic
+ // pixel paths add no observer, so an unobserved container stays unknown).
+ // The released no-container basis is the window WIDTH on both axes; a
+ // vertical region's reported maximum reads the window height instead.
+ if (effectiveMaxPx != null) {
+ effectiveMaxima.set(props, effectiveMaxPx);
+ }
return {
size: isCollapsed ? 0 : size,
@@ -1112,6 +1164,23 @@ function useMultiResizable(
type CollapseControls = {collapse: () => void; expand: () => void};
const collapseControls = new WeakMap<ResizableProps, CollapseControls>();
+/**
+ * The maximum an unbounded region reports as `aria-valuemax`: a measured
+ * extent that stands in for the missing configured maximum — the container's
+ * content box on the active axis while a percentage bound already observes
+ * it, or the window's extent along the axis — floored at the current size
+ * and, while collapsed, at the resolved minimum. The region is never clamped
+ * to it; it is what the separator announces. Kept off the exported
+ * `ResizableProps` for the same reason as the collapse controls;
+ * `getEffectiveMaxPx` is internal.
+ */
+const effectiveMaxima = new WeakMap<ResizableProps, number>();
+
+/** The reported maximum for `props`, or `undefined` for a hand-built object. */
+export function getEffectiveMaxPx(props: ResizableProps): number | undefined {
+ return effectiveMaxima.get(props);
+}
+
/**
* The collapse/expand pair the hook registered for `props`, or `undefined`
* for a hand-built `ResizableProps` object (which the handle then toggles