Skip to content

Commit 4f2fd44

Browse files
committed
feat(TreeList): page content below the tree moves with an expansion
The expansion moved the rows below the group inside the tree, but page content below the tree still moved by layout: it jumped down at an expand and up at the end of a collapse. It now moves on the same spring as the rows (utils/rowMotion.ts contentBelow: in-flow content after the tree, up to its scroll container, that sits below it; positioned and sticky elements and anything another owner already translates or animates are left to layout). A transient individual translate, cleared at rest. followingContent="stays" keeps it still for apps that manage that area. Row motions now go through one shared animator per element (utils/rowMotion.ts, a shim with the signature of the motion foundation's coming animatorFor).
1 parent 153a3ae commit 4f2fd44

9 files changed

Lines changed: 436 additions & 87 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+
[feat] On a touch screen, page content below a `TreeList` moves with a row's expand and collapse, on the same spring as the rows, instead of jumping. `followingContent="stays"` keeps it still for apps that manage that area themselves.
6+
7+
@vjeux

‎apps/storybook/stories/TreeList.stories.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {TreeList} from '@astryxdesign/core/TreeList';
55
import type {TreeListItemData} from '@astryxdesign/core/TreeList';
66
import {Icon} from '@astryxdesign/core/Icon';
77
import {Badge} from '@astryxdesign/core/Badge';
8+
import {Button} from '@astryxdesign/core/Button';
9+
import {VStack} from '@astryxdesign/core/Layout';
810
import {Theme, defineTheme} from '@astryxdesign/core/theme';
911
import {
1012
FolderIcon,
@@ -73,6 +75,24 @@ export const Basic: Story = {
7375
},
7476
};
7577

78+
export const WithContentBelow: Story = {
79+
render: () => (
80+
<VStack gap={4}>
81+
<TreeList items={fileTreeItems} />
82+
<Button label="Open folder" onClick={() => {}} />
83+
</VStack>
84+
),
85+
parameters: {
86+
docs: {
87+
description: {
88+
story:
89+
'On a touch screen, expanding or collapsing a folder moves the ' +
90+
'content below the tree along with the rows.',
91+
},
92+
},
93+
},
94+
};
95+
7696
export const FullyExpanded: Story = {
7797
args: {
7898
items: [

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export const docs = {
118118
'Visual treatment of the hierarchy guide lines. lineGuides shows connector lines; noGuides hides them, keeping indentation. Orthogonal to density.',
119119
default: "'lineGuides'",
120120
},
121+
{
122+
name: 'followingContent',
123+
type: "'moves' | 'stays'",
124+
description:
125+
"On a touch screen, expanding or collapsing a row slides the rows below it, and page content below the tree moves with them (a transient translate, cleared at rest). Use 'stays' to keep the content below the tree still when the app manages that area itself.",
126+
default: "'moves'",
127+
},
121128
{
122129
name: 'header',
123130
type: 'ReactNode',
@@ -199,6 +206,13 @@ export const docsZh = {
199206
'层级引导线的视觉呈现。lineGuides 显示连接线;noGuides 隐藏连接线并保留缩进。与 density 正交。',
200207
default: "'lineGuides'",
201208
},
209+
{
210+
name: 'followingContent',
211+
type: "'moves' | 'stays'",
212+
description:
213+
"在触摸屏上,展开或折叠某一行时其下方的行会滑动,树下方的页面内容也随之移动(临时的 translate,静止后清除)。若应用自行管理该区域,使用 'stays' 让树下方的内容保持不动。",
214+
default: "'moves'",
215+
},
202216
{
203217
name: 'header',
204218
type: 'ReactNode',

‎packages/core/src/TreeList/TreeList.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export interface TreeListProps extends BaseProps<HTMLDivElement> {
6464
*/
6565
variant?: TreeListVariant;
6666

67+
/**
68+
* On a touch screen a row's expand and collapse slide the rows below it,
69+
* and page content below the tree moves with them (a transient
70+
* `translate`, cleared at rest). `'stays'` keeps the content below the tree
71+
* still, for apps that manage that area themselves.
72+
* @default 'moves'
73+
*/
74+
followingContent?: 'moves' | 'stays';
75+
6776
/**
6877
* Header content rendered above the tree list.
6978
* Semantically associated via aria-labelledby.
@@ -187,6 +196,7 @@ export function TreeList({
187196
items,
188197
density = 'balanced',
189198
variant = 'lineGuides',
199+
followingContent = 'moves',
190200
header,
191201
xstyle,
192202
className,
@@ -355,6 +365,7 @@ export function TreeList({
355365
onToggle={handleToggle}
356366
density={density}
357367
variant={variant}
368+
followingContent={followingContent}
358369
renderChildren={renderChildren}
359370
posInSet={index + 1}
360371
setSize={items.length}

‎packages/core/src/TreeList/TreeListItem.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ export interface TreeListItemInternalProps {
368368
* guide element).
369369
*/
370370
variant: TreeListVariant;
371+
/** Whether page content below the tree moves with an expansion. */
372+
followingContent: 'moves' | 'stays';
371373
/**
372374
* Renders the children subtree (the parent recursion), called while the
373375
* row shows its children: expanded, or sliding them away after a collapse.
@@ -412,13 +414,17 @@ export function TreeListItem({
412414
onToggle,
413415
density,
414416
variant,
417+
followingContent,
415418
renderChildren,
416419
posInSet,
417420
setSize,
418421
isTabbable,
419422
}: TreeListItemInternalProps) {
420423
const pressable = usePressFeedback();
421-
const {showsChildren, groupRef} = useTreeExpansionMotion(isExpanded);
424+
const {showsChildren, groupRef} = useTreeExpansionMotion(
425+
isExpanded,
426+
followingContent,
427+
);
422428
const renderedChildren = showsChildren ? renderChildren?.() : undefined;
423429
const t = useTranslator();
424430
const labelId = useId();

‎packages/core/src/TreeList/__tests__/TreeListExpand.interaction.browser.spec.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,65 @@ test('collapse: the children slide back under the parent, then leave, with no ju
228228
expect((await below.boundingBox())?.y ?? 0).toBeCloseTo(belowCollapsed, 0);
229229
});
230230

231+
test('content below the tree moves with the rows, out and back, with no jump', async ({
232+
page,
233+
}) => {
234+
await openStory(page, storybook(), 'core-treelist--with-content-below');
235+
const touch = await page.evaluate(
236+
() => matchMedia('(pointer: coarse)').matches,
237+
);
238+
test.skip(!touch, 'the expansion moves on a touch screen only');
239+
const button = page.getByRole('button', {name: 'Open folder'});
240+
const {group, below} = parts(page);
241+
await expect(button).toBeVisible();
242+
const rest = (await button.boundingBox())?.y ?? 0;
243+
await tapToggle(page);
244+
await holdAnimations(page);
245+
await seekAnimations(page, 0);
246+
const height = await group.evaluate(el => (el as HTMLElement).offsetHeight);
247+
// On screen where it was: its new layout, one group height back up.
248+
expect(await translateY(button)).toBeCloseTo(-height, 0);
249+
// In step with the rows below inside the tree.
250+
await seekAnimations(page, SETTLE_MS / 4);
251+
expect(await translateY(button)).toBeCloseTo(await translateY(below), 1);
252+
await releaseAnimations(page, {finish: true});
253+
await expect.poll(async () => translateY(button)).toBe(0);
254+
expect(((await button.boundingBox())?.y ?? 0) - rest).toBeCloseTo(height, 0);
255+
256+
await tapToggle(page);
257+
await holdAnimations(page);
258+
await seekAnimations(page, SETTLE_MS / 3);
259+
const midway = await translateY(button);
260+
expect(midway).toBeLessThan(-1);
261+
expect(midway).toBeGreaterThan(-height + 1);
262+
await releaseAnimations(page, {finish: true});
263+
await expect(group).toHaveCount(0);
264+
expect(await translateY(button)).toBe(0);
265+
expect((await button.boundingBox())?.y ?? 0).toBeCloseTo(rest, 0);
266+
});
267+
268+
test(
269+
'storyboard: content below the tree moving with an expansion',
270+
{tag: '@storyboard'},
271+
async ({page}, testInfo) => {
272+
await openStory(page, storybook(), 'core-treelist--with-content-below');
273+
const touch = await page.evaluate(
274+
() => matchMedia('(pointer: coarse)').matches,
275+
);
276+
test.skip(!touch, 'the expansion moves on a touch screen only');
277+
await tapToggle(page);
278+
const {storyboard} = await animationStoryboard(page, {
279+
name: 'tree-list-expand-content-below',
280+
clip: {x: 0, y: 0, width: 402, height: 600},
281+
times: [0, 33, 67, 100, 150, 200, 267, Math.round(SETTLE_MS)],
282+
columns: 8,
283+
cellScale: 0.45,
284+
});
285+
await releaseAnimations(page, {finish: true});
286+
await storyboard.write(testInfo);
287+
},
288+
);
289+
231290
test('the rows below keep moving on every frame while the main thread is blocked', async ({
232291
page,
233292
browserName,

‎packages/core/src/TreeList/useTreeExpansionMotion.test.tsx‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* @output Unit tests for the expansion's presence rules: with a mouse a
77
* collapse removes the children at once; on a touch screen they stay,
88
* inert and out of the arrow keys' reach, until they have slid away, and an
9-
* expand that interrupts the collapse keeps them
9+
* expand that interrupts the collapse keeps them; page content below the
10+
* tree moves with an expansion unless the tree keeps it still
1011
* @position Beside TreeList/useTreeExpansionMotion.ts; the motion itself is
1112
* proven in a real engine by
1213
* TreeList/__tests__/TreeListExpand.interaction.browser.spec.ts
@@ -16,6 +17,7 @@ import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';
1617
import {afterEach, describe, expect, it, vi} from 'vitest';
1718
import {TreeList} from './TreeList';
1819
import type {TreeListItemData} from './TreeListTypes';
20+
import {motionOf} from '../utils/rowMotion';
1921

2022
const items: TreeListItemData[] = [
2123
{
@@ -104,3 +106,41 @@ describe('TreeList expansion presence', () => {
104106
expect(screen.getByText('Card.tsx')).toBeInTheDocument();
105107
});
106108
});
109+
110+
describe('content below the tree', () => {
111+
const collapsed: TreeListItemData[] = [
112+
{
113+
id: 'components',
114+
label: 'components',
115+
children: [{id: 'button', label: 'Button.tsx'}],
116+
},
117+
{id: 'app', label: 'App.tsx'},
118+
];
119+
120+
function Page({followingContent}: {followingContent?: 'moves' | 'stays'}) {
121+
return (
122+
<div>
123+
<TreeList items={collapsed} followingContent={followingContent} />
124+
<p data-testid="below">Below the tree</p>
125+
</div>
126+
);
127+
}
128+
129+
it('moves with an expansion on a touch screen', async () => {
130+
stubPointer(true);
131+
render(<Page />);
132+
await act(async () => undefined);
133+
fireEvent.click(toggle() as HTMLElement);
134+
expect(motionOf(screen.getByTestId('below'))).toBeDefined();
135+
});
136+
137+
it("stays still with followingContent: 'stays'", async () => {
138+
stubPointer(true);
139+
render(<Page followingContent="stays" />);
140+
await act(async () => undefined);
141+
fireEvent.click(toggle() as HTMLElement);
142+
expect(motionOf(screen.getByTestId('below'))).toBeUndefined();
143+
// The rows inside the tree still move.
144+
expect(motionOf(row('app') as HTMLElement)).toBeDefined();
145+
});
146+
});

0 commit comments

Comments
 (0)