An open source design system that's fully customizable and agent ready
TypeScript
fix(ResizeHandle): Enter and double-click restore a collapsed pane to its previous size (#7479)
Cindy Zhang458a74c2a65a
diff --git a/.changeset/resize-handle-enter-restores.md b/.changeset/resize-handle-enter-restores.mdnew file mode 100644index 0000000000..f1654e3c34--- /dev/null+++ b/.changeset/resize-handle-enter-restores.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `ResizeHandle`: Enter and double-click on a collapsed pane restore it to the size it had before it collapsed, not to its minimum, and reopen it even when `minSize` is below `collapsedSize`. The handle uses `useResizable`'s own collapse and expand transitions; `ResizableProps` is unchanged, and a hand-built props object keeps the previous resize-to-minimum behavior.++@cixzhangdiff --git a/packages/core/src/Resizable/ResizeHandle.test.tsx b/packages/core/src/Resizable/ResizeHandle.test.tsxindex 9407a9918e..c935ab9454 100644--- a/packages/core/src/Resizable/ResizeHandle.test.tsx+++ b/packages/core/src/Resizable/ResizeHandle.test.tsx@@ -202,6 +202,88 @@ describe('ResizeHandle', () => {expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');});+ it('restores the previous size, not the minimum, when Enter reopens a collapsed pane', () => {+ render(+ <Harness+ config={{+ defaultSize: 300,+ minSize: 100,+ maxSize: 400,+ collapsible: true,+ }}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ fireEvent.keyDown(separator, {key: 'Enter'});+ expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');+ fireEvent.keyDown(separator, {key: 'Enter'});+ expect(separator).not.toHaveAttribute('aria-valuetext');+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ });++ it('restores the previous size, not the minimum, when a double-click reopens a collapsed pane', () => {+ render(+ <Harness+ config={{+ defaultSize: 300,+ minSize: 100,+ maxSize: 400,+ collapsible: true,+ }}+ />,+ );+ const separator = getSeparator();+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ fireEvent.doubleClick(separator);+ expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');+ fireEvent.doubleClick(separator);+ expect(separator).not.toHaveAttribute('aria-valuetext');+ expect(separator).toHaveAttribute('aria-valuenow', '300');+ });++ it('reopens on a double-click even when the minimum size sits below the collapse threshold', () => {+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 20,+ maxSize: 400,+ collapsible: true,+ collapsedSize: 50,+ }}+ />,+ );+ const separator = getSeparator();+ fireEvent.doubleClick(separator);+ expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');+ fireEvent.doubleClick(separator);+ expect(separator).not.toHaveAttribute('aria-valuetext');+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ });++ it('reopens on Enter even when the minimum size sits below the collapse threshold', () => {+ render(+ <Harness+ config={{+ defaultSize: 200,+ minSize: 20,+ maxSize: 400,+ collapsible: true,+ collapsedSize: 50,+ }}+ />,+ );+ const separator = getSeparator();+ act(() => separator.focus());+ fireEvent.keyDown(separator, {key: 'Enter'});+ expect(separator).toHaveAttribute('aria-valuetext', 'Collapsed');+ fireEvent.keyDown(separator, {key: 'Enter'});+ expect(separator).not.toHaveAttribute('aria-valuetext');+ expect(separator).toHaveAttribute('aria-valuenow', '200');+ });+it('keeps aria-valuenow >= aria-valuemin and announces "Collapsed" while collapsed', () => {render(<Harness@@ -243,7 +325,8 @@ describe('ResizeHandle', () => {fireEvent.keyDown(separator, {key: 'Enter'}); // expand againexpect(separator).not.toHaveAttribute('aria-valuetext');- expect(separator).toHaveAttribute('aria-valuenow', '100');+ // Back to the size it had before collapsing, not the minimum.+ expect(separator).toHaveAttribute('aria-valuenow', '200');});// --- Disabled guard ---diff --git a/packages/core/src/Resizable/ResizeHandle.tsx b/packages/core/src/Resizable/ResizeHandle.tsxindex bf30df658c..548f7c9522 100644--- a/packages/core/src/Resizable/ResizeHandle.tsx+++ b/packages/core/src/Resizable/ResizeHandle.tsx@@ -46,7 +46,7 @@ import {} from '../theme/tokens.stylex';import {focusOutlineProps} from '../utils/focusOutline.stylex';import {mergeProps, rtlStyles} from '../utils';-import type {ResizableProps} from './useResizable';+import {getCollapseControls, type ResizableProps} from './useResizable';import {themeProps} from '../utils/themeProps';import {useTranslator} from '../i18n';@@ -360,6 +360,31 @@ export interface ResizeHandleProps extends Omit<children?: ReactNode;}+/**+ * 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+ * previous position"). The hook's own collapse/expand do exactly that; a+ * hand-built `ResizableProps` (no registered controls) falls back to a resize+ * gesture to the minimum, which also cannot reopen a pane whose minimum sits below its+ * collapse threshold.+ */+function toggleCollapse(resizable: ResizableProps): void {+ const controls = getCollapseControls(resizable);+ if (controls) {+ if (resizable._isCollapsed) {+ controls.expand();+ } else {+ controls.collapse();+ }+ return;+ }+ resizable._onResizeStart();+ resizable._onResizeMove(+ resizable._isCollapsed ? resizable._minSizePx : -resizable._size,+ );+ resizable._onResizeEnd();+}+/*** Draggable resize handle placed between resizable panels. Renders as a thin* divider line with a wider invisible hit area and optional pill grip indicator.@@ -375,6 +400,7 @@ export interface ResizeHandleProps extends Omit<* hasDivider />* ```*/+export function ResizeHandle({direction = 'horizontal',position: positionMode = 'inline',@@ -564,11 +590,7 @@ export function ResizeHandle({case 'Enter': {e.preventDefault();if (resizable._collapsible) {- resizable._onResizeStart();- resizable._onResizeMove(- resizable._isCollapsed ? resizable._minSizePx : -resizable._size,- );- resizable._onResizeEnd();+ toggleCollapse(resizable);}break;}@@ -582,11 +604,7 @@ export function ResizeHandle({if (isDisabled || !resizable || !resizable._collapsible) {return;}- resizable._onResizeStart();- resizable._onResizeMove(- resizable._isCollapsed ? resizable._minSizePx : -resizable._size,- );- resizable._onResizeEnd();+ toggleCollapse(resizable);}, [isDisabled, resizable]);// --- Cleanup on unmount ---diff --git a/packages/core/src/Resizable/useResizable.ts b/packages/core/src/Resizable/useResizable.tsindex b48b4b06b6..c61c694a71 100644--- a/packages/core/src/Resizable/useResizable.ts+++ b/packages/core/src/Resizable/useResizable.ts@@ -1041,6 +1041,7 @@ function useSingleResizable(config: UseResizableSingleConfig): ResizableRegion {_direction: direction,_isResizableProps: true,};+ collapseControls.set(props, {collapse, expand});return {size: isCollapsed ? 0 : size,@@ -1097,6 +1098,31 @@ function useMultiResizable(// Public API// =============================================================================+/**+ * Collapse/expand for a region, keyed by the `ResizableProps` object the hook+ * returns. A handle's Enter and double-click use them so the pane restores+ * its previous position (APG window splitter) rather than emulating the+ * toggle with a resize to the minimum.+ *+ * Kept off `ResizableProps` on purpose: that type is exported, so a new field+ * on it — optional or underscored — is a public delta. This module-private+ * map and {@link getCollapseControls} are the package's own channel between+ * the hook and the handle; neither is re-exported.+ */+type CollapseControls = {collapse: () => void; expand: () => void};+const collapseControls = new WeakMap<ResizableProps, CollapseControls>();++/**+ * The collapse/expand pair the hook registered for `props`, or `undefined`+ * for a hand-built `ResizableProps` object (which the handle then toggles+ * with a resize gesture). Internal to the package.+ */+export function getCollapseControls(+ props: ResizableProps,+): CollapseControls | undefined {+ return collapseControls.get(props);+}+/** Removed keys must fail even when a variable bypasses excess-property checks. */type RejectRemovedPixelBounds<Config> = Config extends unknown? Config & {minSizePx?: never; maxSizePx?: never}