Skip to content

Commit 6caf11a

Browse files
committed
feat(List): rows on a touch screen are as tall as iOS table rows
On iOS 26.2 a table row is 52 pt at the default text size (the .default, .value1 and .value2 styles) and 62 pt with a subtitle, and the Human Interface Guidelines put iOS controls at 44 pt; a List row under a finger was 40 px, 60 px with a description, and 33 px in compact density. Under (pointer: coarse), ListItem now has a minimum height of 52 px, 62 px with a description, 44 px in compact density, read from the UIKit constants table (list.metrics) through a build-time mirror; a theme's min-height on list-item still wins, and mouse and trackpad lists are unchanged.
1 parent bf924aa commit 6caf11a

8 files changed

Lines changed: 308 additions & 8 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, `List` rows are as tall as iOS table rows: at least 52px, 62px with a description, and at least 44px in `density="compact"`, which used to put rows as short as 33px under a finger. Lists driven by a mouse or a trackpad are unchanged. A theme that sets `min-height` on `list-item` keeps its own value.
6+
7+
@vjeux

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const docs = {
3232
{
3333
name: 'density',
3434
type: "'compact' | 'balanced' | 'spacious'",
35-
description: 'Spacing density for items.',
35+
description: 'Spacing density for items. On a touch screen (a coarse primary pointer), rows are at least 52px tall, 62px with a description, and never shorter than 44px in compact density, as iOS table rows are.',
3636
default: "'balanced'",
3737
},
3838
{

‎packages/core/src/List/List.test.tsx‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {rulesDeclaredFor} from '../__tests__/pressState';
1616
import {List} from './List';
1717
import {ListItem} from './ListItem';
1818
import {ListMarkerScope} from './ListContext';
19+
import {listRowConsts} from './listRow.stylex';
20+
import {list} from '../motion/uikit/list';
1921

2022
describe('List', () => {
2123
it('forwards ListItem align to its Item row unchanged', () => {
@@ -545,6 +547,79 @@ describe('List', () => {
545547
).toBe(false);
546548
});
547549

550+
// ===========================================================================
551+
// Touch row heights
552+
// ===========================================================================
553+
554+
/**
555+
* The element's own min-height declarations, split by whether they sit
556+
* under the touch media query.
557+
*/
558+
function minHeights(el: Element): {touch: string[]; other: string[]} {
559+
const classes = el.className
560+
.split(/\s+/)
561+
.filter(Boolean)
562+
.map(name => `.${name}`);
563+
const out = {touch: [] as string[], other: [] as string[]};
564+
const visit = (rules: CSSRuleList, touch: boolean) => {
565+
for (const rule of Array.from(rules)) {
566+
if (rule instanceof CSSMediaRule) {
567+
visit(
568+
rule.cssRules,
569+
touch || rule.conditionText.includes('pointer: coarse'),
570+
);
571+
} else if (
572+
rule instanceof CSSStyleRule &&
573+
classes.some(cls => rule.selectorText.startsWith(cls)) &&
574+
rule.style.minHeight !== ''
575+
) {
576+
(touch ? out.touch : out.other).push(rule.style.minHeight);
577+
}
578+
}
579+
};
580+
for (const sheet of Array.from(document.styleSheets)) {
581+
visit(sheet.cssRules, false);
582+
}
583+
return out;
584+
}
585+
586+
it('mirrors the constants table’s touch row heights for the stylesheet', () => {
587+
expect(listRowConsts.touchRowHeight).toBe(`${list.metrics.rowHeight}px`);
588+
expect(listRowConsts.touchSubtitleRowHeight).toBe(
589+
`${list.metrics.subtitleRowHeight}px`,
590+
);
591+
expect(listRowConsts.touchControlSize).toBe(
592+
`${list.metrics.controlSize}px`,
593+
);
594+
});
595+
596+
it('gives rows UIKit’s table heights on a touch screen only', () => {
597+
render(
598+
<>
599+
<List>
600+
<ListItem label="One line" />
601+
<ListItem label="Two lines" description="A description" />
602+
</List>
603+
<List density="compact">
604+
<ListItem label="Compact" description="Still the control size" />
605+
</List>
606+
<List density="spacious">
607+
<ListItem label="Spacious" />
608+
<ListItem label="Spacious two" description="A description" />
609+
</List>
610+
</>,
611+
);
612+
const row = (text: string) => screen.getByText(text).closest('li')!;
613+
expect(minHeights(row('One line')).touch).toEqual(['52px']);
614+
expect(minHeights(row('Two lines')).touch).toEqual(['62px']);
615+
expect(minHeights(row('Compact')).touch).toEqual(['44px']);
616+
// Spacious keeps its own padding over the same minimums.
617+
expect(minHeights(row('Spacious')).touch).toEqual(['52px']);
618+
expect(minHeights(row('Spacious two')).touch).toEqual(['62px']);
619+
// Nothing outside the touch query: a mouse-driven list is unchanged.
620+
expect(minHeights(row('One line')).other).toEqual([]);
621+
});
622+
548623
// ===========================================================================
549624
// Interactive items — onClick (invisible button pattern)
550625
// ===========================================================================

‎packages/core/src/List/List.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export interface ListProps extends BaseProps<
5353
* - 'compact': Tighter spacing for dense UIs
5454
* - 'balanced': Standard spacing
5555
* - 'spacious': Extra spacing for readability
56+
*
57+
* On a touch screen (a coarse primary pointer), rows are at least 52px
58+
* tall, 62px with a description, and never shorter than 44px in compact
59+
* density, as iOS table rows are.
5660
* @default 'balanced'
5761
*/
5862
density?: ListDensity;

‎packages/core/src/List/ListItem.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
/**
66
* @file ListItem.tsx
77
* @input Uses React, ReactNode, StyleXStyles, theme tokens, the List row edge
8-
* treatment, the press layer (dividers beside a touch-pressed row hide and
9-
* the layer reaches over the row's own), CheckboxInput, and the marker or task checkbox a
8+
* treatment, the press layer (dividers beside a touch-pressed or held row
9+
* hide and the layer reaches over the row's own), the touch row heights
10+
* (listRow.stylex.ts), CheckboxInput, and the marker or task checkbox a
1011
* ListMarkerScope sets (Markdown's nested lists and the task items of mixed
1112
* lists)
1213
* @output Exports ListItem component, ListItemProps type
@@ -35,10 +36,11 @@ import {
3536
import type {BaseProps} from '../BaseProps';
3637
import {ListContext, type ListMarker} from './ListContext';
3738
import {CheckboxInput} from '../CheckboxInput';
38-
import {mergeProps} from '../utils';
39+
import {isRenderable, mergeProps} from '../utils';
3940
import {Item} from '../Item';
4041
import type {ItemAlign, ItemSwipeActions, ItemSwipeBehavior} from '../Item';
4142
import {themeProps} from '../utils/themeProps';
43+
import {listRowStyles} from './listRow.stylex';
4244

4345
// =============================================================================
4446
// Types
@@ -314,6 +316,11 @@ const NUMBER_STYLES = {
314316
'lower-roman': markerStyles.lowerRoman,
315317
} as const;
316318

319+
/**
320+
* A row's height on a touch screen (primary pointer coarse): UIKit's table
321+
* rows (`list.metrics`), at least that tall, never shorter than the
322+
* platform's control size. A theme's `min-height` on `list-item` replaces it.
323+
*/
317324
const embeddedStyles = stylex.create({
318325
noRadius: {
319326
borderRadius: 0,
@@ -422,6 +429,11 @@ export function ListItem({
422429
hasMarkers && styles.withCounter,
423430
hasDividers && styles.withDivider,
424431
hasDividers && embeddedStyles.noRadius,
432+
density === 'compact'
433+
? listRowStyles.touchCompact
434+
: isRenderable(description)
435+
? listRowStyles.touchTwoLine
436+
: listRowStyles.touchOneLine,
425437
edge === 'flush' && styles.edgeFlush,
426438
edge === 'outset' && styles.edgeOutset,
427439
edge === 'bleed' && styles.edgeBleed,
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file ListTouchRows.interaction.browser.spec.ts
5+
* @input The built List stories in the touch phone context (primary pointer
6+
* coarse) and the row heights from the UIKit constants table
7+
* (motion/uikit/list.ts)
8+
* @output Layout proofs for List rows on a touch screen: a one-line row is
9+
* UIKit's table row height, a row with a description its subtitle height,
10+
* a compact row the platform's control size, dividers included; a
11+
* storyboard of the three
12+
* @position Interaction evidence for ListItem's touch row heights
13+
* (listRow.stylex.ts)
14+
*/
15+
16+
import {expect, test, type Page} from '@playwright/test';
17+
import {
18+
openStory,
19+
Storyboard,
20+
withStorybook,
21+
} from '@astryxdesign/interaction-harness';
22+
import {list} from '../../motion/uikit/list';
23+
24+
const storybook = withStorybook(test);
25+
26+
async function rowHeights(page: Page): Promise<number[]> {
27+
// The story's rows (Storybook's own hidden error page has list items too).
28+
return page
29+
.locator('#storybook-root li')
30+
.evaluateAll(rows =>
31+
rows.map(row => Math.round(row.getBoundingClientRect().height)),
32+
);
33+
}
34+
35+
const isTouch = async (page: Page) =>
36+
page.evaluate(() => matchMedia('(pointer: coarse)').matches);
37+
38+
const CASES = [
39+
{
40+
story: 'core-list--interactive',
41+
what: 'a one-line row is UIKit’s table row height',
42+
height: list.metrics.rowHeight,
43+
},
44+
{
45+
story: 'core-list--basic',
46+
what: 'a row with a description is UIKit’s subtitle row height',
47+
height: list.metrics.subtitleRowHeight,
48+
},
49+
{
50+
story: 'core-list--compact',
51+
what: 'a compact row, divider included, is the platform’s control size',
52+
height: list.metrics.controlSize,
53+
},
54+
] as const;
55+
56+
test('on a touch screen, spacious density keeps its padding over the same minimum', async ({
57+
page,
58+
}) => {
59+
await openStory(page, storybook(), 'core-list--spacious');
60+
test.skip(
61+
!(await isTouch(page)),
62+
'this engine reports a fine primary pointer; the touch heights apply under (pointer: coarse)',
63+
);
64+
const rows = await page.locator('#storybook-root li').evaluateAll(elements =>
65+
elements.map(el => {
66+
const style = getComputedStyle(el);
67+
return {
68+
height: el.getBoundingClientRect().height,
69+
paddingTop: style.paddingTop,
70+
minHeight: style.minHeight,
71+
};
72+
}),
73+
);
74+
expect(rows.length).toBeGreaterThan(0);
75+
for (const row of rows) {
76+
// Its rows have descriptions: the subtitle minimum, which spacious
77+
// padding already exceeds, so the row keeps its own taller height.
78+
expect(row.minHeight).toBe(`${list.metrics.subtitleRowHeight}px`);
79+
expect(row.paddingTop).toBe('12px');
80+
expect(row.height).toBeGreaterThanOrEqual(list.metrics.subtitleRowHeight);
81+
}
82+
});
83+
84+
for (const {story, what, height} of CASES) {
85+
test(`on a touch screen, ${what}`, async ({page}) => {
86+
await openStory(page, storybook(), story);
87+
test.skip(
88+
!(await isTouch(page)),
89+
'this engine reports a fine primary pointer; the touch heights apply under (pointer: coarse)',
90+
);
91+
const heights = await rowHeights(page);
92+
expect(heights.length).toBeGreaterThan(0);
93+
for (const h of heights) {
94+
expect(h).toBe(height);
95+
}
96+
});
97+
}
98+
99+
test('storyboard: List rows on a touch screen @storyboard', async ({
100+
page,
101+
}, testInfo) => {
102+
test.skip(
103+
testInfo.project.name !== 'chromium',
104+
'One engine is enough for the record',
105+
);
106+
const storyboard = new Storyboard(page, {
107+
name: 'list-touch-rows',
108+
columns: 3,
109+
cellScale: 0.6,
110+
});
111+
for (const {story} of CASES) {
112+
await openStory(page, storybook(), story);
113+
// One clip size for every cell of the sheet.
114+
await page.setViewportSize({width: 402, height: 714});
115+
await storyboard.capture(story, 0, {rows: await rowHeights(page)});
116+
}
117+
await storyboard.write(testInfo);
118+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/**
4+
* @file listRow.stylex.ts
5+
* @input Uses StyleX
6+
* @output Exports `listRowConsts` (the build-time mirror of the touch row
7+
* heights in motion/uikit/list.ts, `list.metrics`) and `listRowStyles` (a
8+
* row's minimum height under the touch media query)
9+
* @position Internal styling utility; ListItem composes `listRowStyles`
10+
*
11+
* StyleX evaluates a style at build time and cannot read the constants
12+
* table, so these are the table's `list.metrics` values as CSS lengths, and
13+
* List.test.tsx fails if they drift. They are sizes, not motion: a theme
14+
* that sets a `min-height` on its `list-item` target replaces them.
15+
*
16+
* The styles live beside the constants on purpose: StyleX inlines a
17+
* `defineConsts` value it reads in the same file, while a value imported
18+
* into another file compiles to a custom property reference that the
19+
* production build never defines.
20+
*
21+
* SYNC: When modified, update motion/uikit/list.ts and List.test.tsx.
22+
*/
23+
24+
import * as stylex from '@stylexjs/stylex';
25+
26+
export const listRowConsts = stylex.defineConsts({
27+
/** `list.metrics.rowHeight`: a one-line row on a touch screen. */
28+
touchRowHeight: '52px',
29+
/** `list.metrics.subtitleRowHeight`: a row with a description. */
30+
touchSubtitleRowHeight: '62px',
31+
/** `list.metrics.controlSize`: the floor of a compact touch row. */
32+
touchControlSize: '44px',
33+
});
34+
35+
/**
36+
* The touch presentation's query (utils/touchPresentation.ts TOUCH_QUERY),
37+
* written out: StyleX needs a literal media key.
38+
*/
39+
const TOUCH = '@media (pointer: coarse)';
40+
41+
/**
42+
* A row's height on a touch screen (primary pointer coarse): UIKit's table
43+
* rows, at least that tall, never shorter than the platform's control size.
44+
* A theme's `min-height` on `list-item` replaces it.
45+
*/
46+
export const listRowStyles = stylex.create({
47+
touchOneLine: {
48+
minHeight: {default: null, [TOUCH]: listRowConsts.touchRowHeight},
49+
},
50+
touchTwoLine: {
51+
minHeight: {default: null, [TOUCH]: listRowConsts.touchSubtitleRowHeight},
52+
},
53+
touchCompact: {
54+
minHeight: {default: null, [TOUCH]: listRowConsts.touchControlSize},
55+
},
56+
});

0 commit comments

Comments
 (0)