Skip to content

Commit b377b21

Browse files
authored
fix(Resizable): the Grab zone stays on the Handle whatever pillPlacement says, and a short item keeps its own drag (#9529)
* test(Resizable): the Grab zone stays on the Handle whatever pillPlacement says, and a short item keeps half of itself for its own drag (component:Resizable FR1) A browser fixture story draws a calendar column at 48px an hour with a 30-minute and a 15-minute event, each moved by a drag on its body and resized by the ResizeHandle on its bottom edge. Red before the fix: - with pillPlacement auto, start or end, the Grab zone's centre sits 5.5 to 8.5px off the Handle's, because it follows the pill; - the zone covers 13.5px of the 24px event with the pill on the event's side, and 8px of the 15-minute event's 12px even when centred, so the events' own drag misses points of their upper half; - the same holds for position="overlay". A drag on the 30-minute event's body moves it, and a drag on its Handle's line resizes it. * fix(Resizable): the Grab zone stays on the Handle whatever pillPlacement says, and takes at most half of a short pane (component:Resizable FR1) FR1 puts the Grab zone, a --spacing-4 strip on the resize axis, on the Handle; pillPlacement only places the pill. The zone followed the pill instead, shifting up to a strip's width toward it, so on a short item (a 30-minute calendar event resized from its edge) it took most of the item and stole its own drag. The zone now sits centred on the Handle for every pillPlacement. On a pane shorter than the zone, it takes at most half the pane, as spec:AST-094 FR42's grown targets stop at half the gap: an inline Handle's zone is at most the pane's length, so half of it reaches into the pane, and an overlay Handle takes at most half of the pane it sits in, with the zone kept inside it. A collapsed pane keeps the whole zone, which reopens it. The unit tests that pinned the zone to the pill now pin it to the Handle, with one for the short-pane limit and the collapsed pane; the docs say pillPlacement moves only the pill, and a [fix] changeset records it. * test(Resizable): a pane at 0px that is not collapsed keeps the whole Grab zone A region at 0px that is not collapsed gets a zero-length inline zone (min(var(--spacing-4), 0px)) and an overlay Handle clamped to half of nothing, so no drag can reopen it. Both cases fail here. * fix(Resizable): a pane at 0px that is not collapsed keeps the whole Grab zone A pane with no length has nothing to protect, so it is treated like a collapsed one: the inline zone and the overlay Handle keep their full length, and a drag can reopen the pane. The duplicate comment at the zone's call site goes. * test(Resizable): a drag on the Grip pill resizes wherever the pill sits With the Grab zone centred on the Handle, a pill that pillPlacement draws outside the zone takes no pointer: on an overlay Handle the start pill sits before the Handle's box, so a drag on it moves a 30-minute event instead of resizing it, and an inline end pill on a short pane hangs past the zone's end. The browser spec drags the pill's centre for every pillPlacement and both positions, and the unit test starts a drag from the pill. The upper-half check now skips the pill's own box. * fix(Resizable): the Grip pill takes the pointer wherever it sits The pill is the Grip, so it stays grabbable wherever pillPlacement paints it: while it is painted, it takes the same pointer handlers as the Grab zone, with the resize cursor, and a hidden or disabled pill takes none. The Grab zone keeps its short-pane limit, and pillPlacement still moves only the pill. The docs and the [fix] changeset say so, and the changeset now says that an overlay Handle takes at most half of the pane it sits in. * docs(Resizable): Grab zone comments in short sentences Each comment sentence the Grab zone change adds has at most 20 words, and the test comment cites no record. ResizeHandle's header drops the paragraph on the pill's dynamic offset, which now sits on that style. No code change. * docs(Resizable): component:Resizable FR1 says where the grab zone sits and how it shrinks on a short pane FR1 named the Grab zone only as a --spacing-4 strip. It now adds the owner's ruling, word for word: the grab zone is centred on the Handle for every pillPlacement, and the painted pill is its own grab target; on a pane too short for the full strip, the zone shrinks so the pane keeps at least half of itself. FR1's basis names the owner ruling, and its verification row names the browser spec that checks the zone's place and its short-pane limit. * docs(Resizable): ResizeHandle's header says a drag takes capture where it starts, and a restating comment goes A drag that starts on the Grip pill takes capture on the pill, not on the grab zone, so the header names the element the drag starts on. The comment over the overlay zone's width restated its min(…, 100%). * test(Resizable): a pill shown on hover beside an overlay Handle stays reachable from the Grab zone An overlay Handle can draw its pill outside the Grab zone: at start in left-to-right, and at end in right-to-left. A pill that shows only on hover then hides as the pointer leaves the zone to reach it, and a drag from where it showed does nothing. A story puts a hover-revealed pill beside an overlay Handle, and the browser spec crosses from the zone to the pill and drags it, in both directions. They fail here: the size stays 250 after the drag. * fix(Resizable): a pill shown on hover stays reachable from the Grab zone An overlay Handle can draw its pill outside the Grab zone, so the pointer leaves the zone to reach it. The hover now stays for 150 ms after the pointer leaves the zone or the pill, and entering either one keeps it. So a hover-revealed pill stays shown and takes the pointer while the pointer crosses to it. The pill's offset functions take -1 | 1. * test(Resizable): a hover-revealed pill stays shown while the pointer rests between the Grab zone and the pill The browser case now rests 300 ms in the gap between the zone and the pill before it reaches the pill and drags. A pointer that pauses on the way must not lose the pill, so the pill has to stay reachable by its geometry, not by a grace time. It fails here: the 150 ms hover grace runs out during the rest, and the pill hides (opacity 0). * fix(Resizable): a hover-revealed pill reaches across the gap to the Grab zone, with no hover timer The 150 ms hover grace was a second hover-timing implementation, which architecture:interaction-modality INV11 keeps in the shared hover recognizer. A pointer that rested in the gap also lost the pill. The pill shown on hover now carries an invisible extension along the resize axis that spans the --spacing-1 gap to the zone. It takes the pointer only while the pill does. The timer and its unmount Effect go. The header keeps its tags and the capture sentence, and the short-pane rule is stated once, where the pane length is read. * test(Resizable): a hover-revealed pill takes no pointer past its far side The hover-pill browser case now checks the point 3 px past the pill's side away from the zone: it must find the pane, not the pill. So the pill's hit area cannot cover more of a short item than the pill does. It fails here: the pill's bridge reaches out on both sides, so the point past the far side finds the pill. * fix(Resizable): a hover-revealed pill's bridge reaches only toward the Handle The pill's invisible extension reached out on both sides along the resize axis. On a short item, its far side covered the item's own drag at the pill's column, past what FR1 lets the pill take. It now spans only the gap toward the Handle, so it reaches no further than the pill. The pill's offset is a physical translate, so the bridge picks its physical side, with logical insets that swap under RTL. * docs(Resizable): FR1 says a hover-revealed pill takes the pointer across the gap to the Grab zone An owner ruling adds the sentence verbatim: a pill shown only on hover also takes the pointer across the gap between it and the Grab zone, never past the pill's far side.
1 parent c19ca12 commit b377b21

9 files changed

Lines changed: 737 additions & 172 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] `ResizeHandle`'s grab zone stays centred on the divider whatever `pillPlacement` says, which now moves only the pill. An inline zone takes at most half of a pane shorter than it, and an overlay Handle takes at most half of the pane it sits in. A short item, such as a 30-minute calendar event resized from its edge, keeps its own drag, and a drag on the pill still resizes wherever the pill is drawn.
6+
7+
@vjeux

‎apps/storybook/rtl-audit/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ spike this guard removed the single false positive.
192192
its parent's width** is skipped: a full-bleed strip spans the _entire_ parent,
193193
so it occupies both halves and has **no left/right side** to land on the wrong
194194
one. This catches `useResizable`'s **vertical** grab zone (`ResizeHandle`'s
195-
`hitAreaOffsetY`): a full-width strip anchored `insetInlineStart:0;
196-
insetInlineEnd:0` with a purely-visual centering `translate(-50%,…)`, so its
195+
`hitAreaCenteredY`): a full-width strip anchored `insetInlineStart:0;
196+
insetInlineEnd:0` and centred on the block axis only, so its
197197
geometric _center_ sits at the parent origin (relCenterX≈0) **identically in LTR
198198
and RTL**. The mirror assertion would otherwise compute `expected = parentW − 0
199199
= parentW` and fire a spurious `Δ = parentW`. The degenerate-parent guard misses

‎apps/storybook/stories/Resizable.stories.tsx‎

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Meta Platforms, Inc. and affiliates.
22

3+
import {useRef, useState} from 'react';
34
import type {Meta, StoryObj} from '@storybook/react';
45
import * as stylex from '@stylexjs/stylex';
56
import {colorVars, radiusVars} from '@astryxdesign/core/theme/tokens.stylex';
@@ -564,3 +565,183 @@ export const WithEmbeddedFrame: Story = {
564565
);
565566
},
566567
};
568+
569+
const cal = stylex.create({
570+
column: {
571+
position: 'relative',
572+
width: 240,
573+
height: 192,
574+
borderWidth: 1,
575+
borderStyle: 'solid',
576+
borderColor: colorVars['--color-border'],
577+
borderRadius: radiusVars['--radius-container'],
578+
},
579+
// A calendar event: its body moves it, and the Handle on its bottom edge
580+
// changes how long it lasts.
581+
event: (top: number, height: number) => ({
582+
position: 'absolute',
583+
insetInlineStart: 8,
584+
insetInlineEnd: 8,
585+
top,
586+
height,
587+
display: 'flex',
588+
flexDirection: 'column',
589+
overflow: 'visible',
590+
borderRadius: radiusVars['--radius-element'],
591+
backgroundColor: colorVars['--color-background-muted'],
592+
}),
593+
eventBody: {
594+
flexGrow: 1,
595+
minHeight: 0,
596+
cursor: 'move',
597+
touchAction: 'none',
598+
},
599+
});
600+
601+
/** At 48px an hour, as a day view draws it. */
602+
const PX_PER_HOUR = 48;
603+
604+
/**
605+
* One event of a calendar column: dragging its body moves it, and its
606+
* ResizeHandle changes its length. The event keeps its own drag however short
607+
* it is: the Grab zone stays on the Handle, whatever `pillPlacement` says, and
608+
* takes at most half the event (component:Resizable FR1).
609+
*/
610+
function CalendarEvent({
611+
testId,
612+
minutes,
613+
initialTop,
614+
pillPlacement,
615+
position,
616+
}: {
617+
testId: string;
618+
minutes: number;
619+
initialTop: number;
620+
pillPlacement: 'auto' | 'start' | 'center' | 'end';
621+
position: 'inline' | 'overlay';
622+
}) {
623+
const length = useResizable({
624+
defaultSize: (minutes / 60) * PX_PER_HOUR,
625+
minSize: PX_PER_HOUR / 8,
626+
direction: 'vertical',
627+
});
628+
const [top, setTop] = useState(initialTop);
629+
const moveRef = useRef<{y: number; top: number} | null>(null);
630+
return (
631+
<div
632+
data-testid={testId}
633+
data-top={top}
634+
{...stylex.props(cal.event(top, length.size))}>
635+
<div
636+
data-testid={`${testId}-body`}
637+
{...stylex.props(cal.eventBody)}
638+
onPointerDown={event => {
639+
moveRef.current = {y: event.clientY, top};
640+
event.currentTarget.setPointerCapture(event.pointerId);
641+
}}
642+
onPointerMove={event => {
643+
const move = moveRef.current;
644+
if (move != null) {
645+
setTop(move.top + event.clientY - move.y);
646+
}
647+
}}
648+
onPointerUp={() => {
649+
moveRef.current = null;
650+
}}>
651+
<Text type="supporting">{minutes} min</Text>
652+
</div>
653+
<ResizeHandle
654+
direction="vertical"
655+
position={position}
656+
pillPlacement={pillPlacement}
657+
resizable={length.props}
658+
label={`Resize the ${minutes}-minute event`}
659+
/>
660+
</div>
661+
);
662+
}
663+
664+
/**
665+
* Browser fixture for the Grab zone on a short item: a 30-minute and a
666+
* 15-minute event, each resized from its bottom edge.
667+
*/
668+
function ShortItems({
669+
pillPlacement,
670+
position,
671+
}: {
672+
pillPlacement: 'auto' | 'start' | 'center' | 'end';
673+
position: 'inline' | 'overlay';
674+
}) {
675+
return (
676+
<div {...stylex.props(cal.column)}>
677+
<CalendarEvent
678+
testId="thirty"
679+
minutes={30}
680+
initialTop={24}
681+
pillPlacement={pillPlacement}
682+
position={position}
683+
/>
684+
<CalendarEvent
685+
testId="fifteen"
686+
minutes={15}
687+
initialTop={120}
688+
pillPlacement={pillPlacement}
689+
position={position}
690+
/>
691+
</div>
692+
);
693+
}
694+
695+
export const GrabZoneOnShortItems: StoryObj<typeof ShortItems> = {
696+
tags: ['!autodocs', 'no-visual'],
697+
args: {pillPlacement: 'auto', position: 'inline'},
698+
render: args => <ShortItems {...args} />,
699+
};
700+
701+
/**
702+
* Browser fixture for a pill that shows on hover beside an overlay Handle.
703+
* The pill can sit outside the Grab zone, so the pointer crosses a gap to
704+
* reach it.
705+
*/
706+
function HoverPillOnOverlay({
707+
pillPlacement,
708+
dir,
709+
}: {
710+
pillPlacement: 'start' | 'end';
711+
dir: 'ltr' | 'rtl';
712+
}) {
713+
const sidebar = useResizable({defaultSize: 250, minSize: 150, maxSize: 500});
714+
return (
715+
<div dir={dir} {...stylex.props(ps.shell)}>
716+
<Layout
717+
height="fill"
718+
start={
719+
<>
720+
<LayoutPanel width={sidebar.size} hasDivider={false}>
721+
<Text>{sidebar.size}px</Text>
722+
</LayoutPanel>
723+
<ResizeHandle
724+
direction="horizontal"
725+
position="overlay"
726+
pillPlacement={pillPlacement}
727+
isAlwaysVisible={false}
728+
resizable={sidebar.props}
729+
label="Resize sidebar"
730+
/>
731+
</>
732+
}
733+
content={
734+
<LayoutContent>
735+
<Heading level={4}>Content</Heading>
736+
</LayoutContent>
737+
}
738+
/>
739+
</div>
740+
);
741+
}
742+
743+
export const HoverPillOnOverlayHandle: StoryObj<typeof HoverPillOnOverlay> = {
744+
tags: ['!autodocs', 'no-visual'],
745+
args: {pillPlacement: 'start', dir: 'ltr'},
746+
render: args => <HoverPillOnOverlay {...args} />,
747+
};

‎docs/specs/components/Resizable/Resizable.spec.md‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

‎packages/core/src/Resizable/Resizable.doc.mjs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ const anatomy = [
1212
name: 'Grip pill',
1313
required: false,
1414
description:
15-
'Default visible grip indicator; custom handle content can replace it.',
15+
'Default visible grip indicator; dragging it resizes, wherever it sits. Custom handle content can replace it.',
1616
},
1717
{
1818
name: 'Grab zone',
1919
required: true,
2020
description:
21-
'Invisible enlarged pointer region aligned with the grip or divider.',
21+
'Invisible enlarged pointer region centred on the divider. An inline zone takes at most half of a pane shorter than it; an overlay handle takes at most half of its pane.',
2222
},
2323
];
2424

@@ -224,7 +224,8 @@ const region = useResizable({
224224
description:
225225
'Which side of the divider the pill sits on. ' +
226226
'auto = content side (derived from isReversed), flips when collapsed. ' +
227-
'start = left/top, end = right/bottom, center = centered on divider.',
227+
'start = left/top, end = right/bottom, center = centered on divider. ' +
228+
'It moves only the pill, which a drag can still take wherever it sits; the grab zone stays centred on the divider.',
228229
default: "'auto'",
229230
},
230231
{
@@ -317,7 +318,7 @@ export const docsDense = {
317318
isAlwaysVisible:
318319
'show pill grip at rest instead of only on hover. Use when discoverability important',
319320
pillPlacement:
320-
'which side of divider pill sits on. auto = content side (derived from isReversed), flips when collapsed; start = left/top, end = right/bottom, center = centered on divider',
321+
'which side of divider pill sits on. auto = content side (derived from isReversed), flips when collapsed; start = left/top, end = right/bottom, center = centered on divider. Moves only the pill (still draggable); grab zone stays on the divider',
321322
label: 'accessible label for separator',
322323
resizable: 'resize props from useResizable: connects handle to panel',
323324
},

‎packages/core/src/Resizable/ResizeHandle.test.tsx‎

Lines changed: 77 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,64 +1107,88 @@ describe('ResizeHandle', () => {
11071107
gcsSpy.mockRestore();
11081108
});
11091109

1110-
// --- Hit-area geometry (grab zone tracks the visible pill) ---
1111-
1112-
it('anchors the biased grab zone with the pill offset and a dir-flipped centering shift', () => {
1113-
// For an off-center pill the hit area must reuse the pill's physical offset
1114-
// construction (anchored at insetInlineStart:0) rather than a divider-
1115-
// relative 50% anchor + percentage bias, so the two stay aligned in LTR and
1116-
// RTL. The half-width-difference centering shift (6.5px) is inline, so it
1117-
// flips physical sign under RTL: `- 6.5px` (LTR) vs `+ 6.5px` (RTL). See the
1118-
// Playwright measurement (hitArea.center === pill.center, 0px offset in both
1119-
// directions) for the geometric proof; here we lock the transform shape.
1120-
render(<Harness handleProps={{pillPlacement: 'start'}} />);
1121-
const hitArea = getSeparator().firstElementChild as HTMLElement;
1122-
expect(hitArea.className).toContain('hitAreaOffsetX');
1123-
const style = hitArea.getAttribute('style') ?? '';
1124-
// LTR (default) branch subtracts the centering shift; RTL branch adds it.
1125-
expect(style).toContain('- 6.5px');
1126-
expect(style).toContain('+ 6.5px');
1127-
});
1110+
// --- Hit-area geometry (the grab zone stays on the Handle) ---
1111+
1112+
// `pillPlacement` places only the pill: the grab zone sits centred on the
1113+
// Handle, through the direction-symmetric rtlStyles.centerInline helper on
1114+
// the inline axis (component:Resizable FR1). The browser proof
1115+
// (grabZone.interaction.browser.spec.ts) measures the geometry.
1116+
it.each(['auto', 'start', 'center', 'end'] as const)(
1117+
'centres the grab zone on the Handle with pillPlacement="%s"',
1118+
pillPlacement => {
1119+
render(<Harness handleProps={{pillPlacement}} />);
1120+
const hitArea = getSeparator().firstElementChild as HTMLElement;
1121+
expect(hitArea.className).toContain('centerInline');
1122+
// centerInline's own centring, and no offset toward the pill.
1123+
expect(hitArea.getAttribute('style') ?? '').toContain(
1124+
'translate(-50%, 0px)',
1125+
);
1126+
expect(hitArea.getAttribute('style') ?? '').not.toContain('6.5px');
1127+
},
1128+
);
11281129

1129-
it('centers the grab zone on the divider when the pill is centered (no bias)', () => {
1130-
render(<Harness handleProps={{pillPlacement: 'center'}} />);
1131-
const hitArea = getSeparator().firstElementChild as HTMLElement;
1132-
// Centered via the shared rtlStyles.centerInline helper (direction-symmetric
1133-
// left+translateX), not a biased offset.
1134-
expect(hitArea.className).toContain('centerInline');
1135-
expect(hitArea.className).not.toContain('hitAreaOffsetX');
1136-
});
1130+
it.each(['auto', 'start', 'center', 'end'] as const)(
1131+
'centres a vertical grab zone on the Handle with pillPlacement="%s"',
1132+
pillPlacement => {
1133+
render(
1134+
<Harness
1135+
config={{defaultSize: 200, direction: 'vertical'}}
1136+
handleProps={{direction: 'vertical', pillPlacement}}
1137+
/>,
1138+
);
1139+
const hitArea = getSeparator().firstElementChild as HTMLElement;
1140+
expect(hitArea.className).toContain('hitAreaCenteredY');
1141+
expect(hitArea.getAttribute('style') ?? '').not.toContain('translate');
1142+
},
1143+
);
11371144

1138-
// The grab zone is stretched along the handle by its 0/0 insets, so anything
1139-
// that moves it across the handle displaces the whole zone off the divider —
1140-
// a percentage does it by half the handle's length, so the taller the panel
1141-
// the larger the dead region, and nothing about it is visible on screen.
1142-
it.each([
1143-
['horizontal' as const, 'translateX'],
1144-
['vertical' as const, 'translateY'],
1145-
])('offsets the %s grab zone along the pill axis only', (direction, axis) => {
1146-
render(
1145+
// On a pane shorter than the zone, the zone reaches at most half the pane.
1146+
// Grown targets stop at half the gap in the same way. A collapsed pane keeps
1147+
// the whole zone, which reopens it.
1148+
it('limits the grab zone to the length of a short pane, and not while it is collapsed', () => {
1149+
const view = render(
11471150
<Harness
1148-
config={{
1149-
defaultSize: 200,
1150-
minSize: 100,
1151-
maxSize: 400,
1152-
direction,
1153-
}}
1154-
handleProps={{direction, pillPlacement: 'start'}}
1151+
config={{defaultSize: 12, minSize: 6, collapsible: true}}
1152+
handleProps={{}}
11551153
/>,
11561154
);
1157-
const hitArea = getSeparator().firstElementChild as HTMLElement;
1158-
const translates = (hitArea.getAttribute('style') ?? '')
1159-
.split(';')
1160-
.map(decl => decl.split(/:(.*)/s)[1]?.trim() ?? '')
1161-
.filter(value => value.startsWith('translate'));
1162-
1163-
// Both the LTR and RTL declarations of the horizontal offset.
1164-
expect(translates.length).toBeGreaterThan(0);
1165-
for (const translate of translates) {
1166-
expect(translate.startsWith(`${axis}(`)).toBe(true);
1167-
}
1155+
const hitArea = () => getSeparator().firstElementChild as HTMLElement;
1156+
expect(hitArea().getAttribute('style') ?? '').toContain('12px');
1157+
fireEvent.keyDown(getSeparator(), {key: 'Enter'});
1158+
expect(getSeparator()).toHaveAttribute('aria-valuetext', 'Collapsed');
1159+
expect(hitArea().getAttribute('style') ?? '').not.toContain('min(');
1160+
view.unmount();
1161+
});
1162+
1163+
// A pane at 0px that is not collapsed has no length to protect. It keeps
1164+
// the whole zone, so a drag can reopen it.
1165+
it.each(['inline', 'overlay'] as const)(
1166+
'keeps the whole grab zone on a pane at 0px that is not collapsed (%s)',
1167+
position => {
1168+
render(
1169+
<Harness
1170+
config={{defaultSize: 0, minSize: 0}}
1171+
handleProps={{position}}
1172+
/>,
1173+
);
1174+
expect(getSeparator()).not.toHaveAttribute('aria-valuetext');
1175+
const hitArea = getSeparator().firstElementChild as HTMLElement;
1176+
expect(hitArea.getAttribute('style') ?? '').not.toContain('min(');
1177+
expect(getSeparator().className).not.toContain('OnShortPane');
1178+
},
1179+
);
1180+
1181+
it('starts a drag from the Grip pill as from the Grab zone', () => {
1182+
const resizable = makeResizable();
1183+
render(<ResizeHandle resizable={resizable} label="Resize" />);
1184+
const pill = getSeparator().querySelector('.astryx-resize-handle-pill');
1185+
expect(pill).not.toBeNull();
1186+
fireEvent.pointerDown(pill as Element, {
1187+
pointerId: 1,
1188+
clientX: 0,
1189+
button: 0,
1190+
});
1191+
expect(resizable._onResizeStart).toHaveBeenCalledTimes(1);
11681192
});
11691193

11701194
// --- Prop composition (ordering choice: handler sits after {...props}) ---

0 commit comments

Comments
 (0)