Skip to content

Commit eb24661

Browse files
committed
fix(console): a sidebar drag cut short by the edge going away ends as a cancel; the changeset names only the i18n key (#36227)
The width handle unmounts mid-drag when ⌘/Ctrl+B folds the sidebar or the window narrows past 768 px. Its unmount now ends the drag as a pointer-cancel does: body cursor and user-select are restored and the preview width is dropped, so the sidebar goes back to the width it had. A test pins both paths. The changeset's Clause-② gloss claimed new exports from the app shell's sidebar module; app-shell is private and re-exports neither, so it now names the one i18n key, as the PR body does. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbWjfzbfpWXFKqr1sFF
1 parent eebb750 commit eb24661

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎.changeset/36227-sidebar-resize-float-card.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
feat(console): the left sidebar resizes by its right edge, the collapsed sidebar floats as a card, and a menu opened from the float no longer leaves it folded with the menu cut off
77

8-
Clause-②: yes (widening) — a new `@object-ui/i18n` key (`sidebar.resize`) in all 11 locales and new exports from the app shell's sidebar module (the width range, its kept preference and the float's classes); no spec, schema or server change
8+
Clause-②: yes (widening) — one new `@object-ui/i18n` key (`sidebar.resize`) in all 11 locales; no spec, schema, server or published export change
99
Metadata-protocol: none
1010

1111
- **Resize** (`@object-ui/app-shell`): from 768 px up, the docked sidebar's right edge drags it between 200 and 350 px; a double-click comes back to 256; ← → move it 16 px, Home and End to either end. The width is kept in this browser (`console.sidebar.width`) and the menu floating over a collapsed sidebar takes it too. A phone's drawer keeps its own width.

‎ui/packages/app-shell/src/layout/SidebarWidthHandle.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ export function SidebarWidthHandle({ width, onPreview, onCommit }: SidebarWidthH
4444
if (commit && start && start.last !== start.width) onCommit(start.last);
4545
};
4646

47+
// The handle can go away mid-drag: ⌘/Ctrl+B folds the sidebar, or the window
48+
// narrows past 768 px, while the edge is still held. The drag then ends as a
49+
// cancel: the page is selectable again and the sidebar goes back to the
50+
// width it had when the drag began, the way a pointer-cancel ends it.
51+
const previewRef = React.useRef(onPreview);
52+
React.useEffect(() => {
53+
previewRef.current = onPreview;
54+
});
55+
React.useEffect(
56+
() => () => {
57+
if (!drag.current) return;
58+
drag.current = null;
59+
document.body.style.removeProperty('cursor');
60+
document.body.style.removeProperty('user-select');
61+
previewRef.current(null);
62+
},
63+
[],
64+
);
65+
4766
return (
4867
<div
4968
role="separator"

‎ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,41 @@ describe('the docked sidebar’s right edge resizes it, and the float takes the
839839
expect(tokens(panel())).not.toContain('left-0');
840840
});
841841

842+
it('the edge going away mid-drag ends the drag as a cancel: the page is selectable again and the width goes back (⌘B, then a narrow window)', () => {
843+
const body = document.body.style;
844+
writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 300);
845+
renderShell(1440);
846+
847+
// ⌘B folds the sidebar while the edge is held.
848+
fireEvent.pointerDown(resizeHandle()!, { button: 0, clientX: 300, pointerId: 1 });
849+
fireEvent.pointerMove(resizeHandle()!, { clientX: 340, pointerId: 1 });
850+
expect(frameWidth()).toBe('340px');
851+
expect(body.getPropertyValue('user-select')).toBe('none');
852+
commandB();
853+
expectHidden();
854+
expect(resizeHandle()).toBeNull();
855+
expect(body.getPropertyValue('user-select'), 'the page is selectable again').toBe('');
856+
expect(body.getPropertyValue('cursor')).toBe('');
857+
expect(frameWidth(), 'back to the width it had').toBe('300px');
858+
expect(tokens(frame())).not.toContain(SIDEBAR_RESIZING_FRAME);
859+
expect(keptWidth()).toBe(300);
860+
861+
// The window narrows past 768 px while the edge is held.
862+
commandB();
863+
expectDocked();
864+
fireEvent.pointerDown(resizeHandle()!, { button: 0, clientX: 300, pointerId: 2 });
865+
fireEvent.pointerMove(resizeHandle()!, { clientX: 220, pointerId: 2 });
866+
expect(body.getPropertyValue('user-select')).toBe('none');
867+
resizeTo(700);
868+
expect(resizeHandle()).toBeNull();
869+
expect(body.getPropertyValue('user-select')).toBe('');
870+
expect(body.getPropertyValue('cursor')).toBe('');
871+
expect(keptWidth()).toBe(300);
872+
resizeTo(1440);
873+
expect(frameWidth(), 'nothing of the drag is left behind').toBe('300px');
874+
expect(tokens(frame())).not.toContain(SIDEBAR_RESIZING_FRAME);
875+
});
876+
842877
it('on a phone the drawer keeps its own width and draws no edge', () => {
843878
writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 300);
844879
renderShell(700);

0 commit comments

Comments
 (0)