Skip to content

Commit e877f69

Browse files
committed
fix(CheckboxInput): a label-hidden checkbox keeps its composer's row under a finger
The 44 px row floor and the 44 × 44 px target applied to every CheckboxInput, including the label-hidden ones other components embed: on a touch screen a MultiSelector option grew from 36 to 56 px, a compact table selection row from 33 to 53 px and a Markdown task item from 32 to 52 px, and a 44 px target would reach into the next, shorter row. Both now apply only to a labelled checkbox, which is its own row; a label-hidden marker keeps its 24 px coarse-pointer target, as on main. The touch-target spec holds the three composers below 44 px with a 24 px target. The touchTarget stylesheet comment no longer names a file this branch doesn't have.
1 parent c99f34a commit e877f69

5 files changed

Lines changed: 72 additions & 9 deletions

File tree

‎.changeset/selection-touch-targets.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
'@astryxdesign/core': patch
33
---
44

5-
[fix] On a touch screen, a checkbox and a radio option are now as easy to hit as an iOS control (44 pt). A standalone CheckboxInput's row is at least 44 px tall, and its target is at least 44 × 44 px, centered on the 20 or 24 px box. Each RadioList row is at least 44 px tall, and the rows touch, so the whole column is target. With a mouse or trackpad the sizes are unchanged. The CheckboxInput `size` docs now give the real box sizes.
5+
[fix] On a touch screen, a checkbox and a radio option are now as easy to hit as an iOS control (44 pt). A standalone, labelled CheckboxInput's row is at least 44 px tall, and its target is at least 44 × 44 px, centered on the 20 or 24 px box; a label-hidden checkbox inside another component's row (a MultiSelector option, a table selection cell, a task item) keeps that row's height and its 24 px target. Each RadioList row is at least 44 px tall, and the rows touch, so the whole column is target. With a mouse or trackpad the sizes are unchanged. The CheckboxInput `size` docs now give the real box sizes.
66

77
@vjeux

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const docs = {
109109
name: 'size',
110110
type: "'sm' | 'md'",
111111
description:
112-
'The size of the checkbox: a 20 px box for sm (compact layouts), 24 px for md (default). Under a coarse pointer the row is at least 44 px tall and the checkbox target at least 44 × 44 px.',
112+
'The size of the checkbox: a 20 px box for sm (compact layouts), 24 px for md (default). Under a coarse pointer a labelled checkbox’s row is at least 44 px tall and its target at least 44 × 44 px; a label-hidden checkbox (a marker in another component’s row) keeps its size.',
113113
default: "'md'",
114114
},
115115
{
@@ -353,7 +353,7 @@ export const docsZh = {
353353
name: 'size',
354354
type: "'sm' | 'md'",
355355
description:
356-
'复选框尺寸:sm 为 20 px 的方框(紧凑布局),md 为 24 px(默认)。在粗指针(触摸)下,行高至少 44 px,复选框的点击区域至少 44 × 44 px。',
356+
'复选框尺寸:sm 为 20 px 的方框(紧凑布局),md 为 24 px(默认)。在粗指针(触摸)下,带可见标签的复选框行高至少 44 px,点击区域至少 44 × 44 px;隐藏标签的复选框(其他组件行内的标记)保持原尺寸。',
357357
default: "'md'",
358358
},
359359
{

‎packages/core/src/CheckboxInput/CheckboxInput.tsx‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ const styles = stylex.create({
137137
},
138138
zIndex: 1,
139139
},
140+
inputCoarse: {
141+
'@media (pointer: coarse)': {
142+
minInlineSize: 24,
143+
minBlockSize: 24,
144+
},
145+
},
140146
inputDisabled: {
141147
cursor: 'default',
142148
},
@@ -436,8 +442,11 @@ export function CheckboxInput({
436442
}}
437443
{...(isDisabled ? undefined : pressable)}
438444
{...stylex.props(
439-
// Under a finger the row is at least as tall as an iOS control.
440-
touchTargetStyles.row,
445+
// Under a finger the row is at least as tall as an iOS control,
446+
// when the checkbox is its own labelled row. A label-hidden
447+
// checkbox is a marker in a composer's row (a MultiSelector option,
448+
// a table's selection cell, a task item), which keeps its height.
449+
!isLabelHidden && touchTargetStyles.row,
441450
styles.container,
442451
isLabelHidden && styles.containerLabelHidden,
443452
// Hover and focus reach the checkbox visual through this ancestor
@@ -504,8 +513,10 @@ export function CheckboxInput({
504513
styles.input,
505514
rtlStyles.centerInline('-50%'),
506515
// Under a finger the input is the control's whole target, 44
507-
// pt each way like an iOS control, centred on the box.
508-
touchTargetStyles.control,
516+
// pt each way like an iOS control, centred on the box. A
517+
// label-hidden marker keeps its 24 px target: in a composer's
518+
// shorter row a 44 px one would reach into the next row.
519+
isLabelHidden ? styles.inputCoarse : touchTargetStyles.control,
509520
wrapperSizeStyles[size],
510521
isDisabled && styles.inputDisabled,
511522
)}

‎packages/core/src/Indicator/__tests__/TouchTargets.interaction.browser.spec.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,58 @@ test.describe('selection controls under a finger', () => {
108108
await expect(page.getByRole('radio').nth(1)).toBeChecked();
109109
});
110110

111+
// A label-hidden checkbox is a marker in a composer's row: the composer
112+
// keeps its row height and the marker its 24 px target, so a taller target
113+
// never reaches into the next row.
114+
for (const [what, story] of [
115+
['a Markdown task item', 'core-markdown--default'],
116+
['a compact table selection cell', 'core-tableselection--compact'],
117+
] as const) {
118+
test(`${what} keeps its height under a finger`, async ({page}) => {
119+
await openStory(page, storybook(), story);
120+
const marker = await page
121+
.locator('#storybook-root input[type="checkbox"]')
122+
.first()
123+
.evaluate(input => {
124+
const row = input.closest('[data-astryx-pressable]');
125+
if (row == null) {
126+
throw new Error('no checkbox row');
127+
}
128+
const r = input.getBoundingClientRect();
129+
return {
130+
row: row.getBoundingClientRect().height,
131+
input: {width: r.width, height: r.height},
132+
};
133+
});
134+
expect(marker.row).toBeLessThan(SIZE);
135+
expect(marker.input.width).toBeLessThanOrEqual(24.5);
136+
expect(marker.input.height).toBeLessThanOrEqual(24.5);
137+
});
138+
}
139+
140+
test('a MultiSelector option keeps its height under a finger', async ({
141+
page,
142+
}) => {
143+
await openStory(page, storybook(), 'core-multiselector--default');
144+
await page.getByRole('combobox').first().tap();
145+
const option = page.getByRole('option').first();
146+
await option.waitFor();
147+
const marker = await option.evaluate(el => {
148+
const input = el.querySelector('input[type="checkbox"]');
149+
if (input == null) {
150+
throw new Error('no checkbox in the option');
151+
}
152+
const r = input.getBoundingClientRect();
153+
return {
154+
option: el.getBoundingClientRect().height,
155+
input: {width: r.width, height: r.height},
156+
};
157+
});
158+
expect(marker.option).toBeLessThan(SIZE);
159+
expect(marker.input.width).toBeLessThanOrEqual(24.5);
160+
expect(marker.input.height).toBeLessThanOrEqual(24.5);
161+
});
162+
111163
test('a mouse keeps the drawn sizes (negative control)', async ({
112164
browser,
113165
}) => {

‎packages/core/src/Indicator/touchTarget.stylex.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export const touchTargetConsts = stylex.defineConsts({
3030
});
3131

3232
/**
33-
* The touch presentation's query (utils/touchPresentation.ts TOUCH_QUERY),
34-
* written out: StyleX needs a literal media key.
33+
* The touch presentation's query, written out: StyleX needs a literal media
34+
* key.
3535
*/
3636
const TOUCH = '@media (pointer: coarse)';
3737

0 commit comments

Comments
 (0)