Skip to content

Commit 2011ce5

Browse files
committed
feat(core): a row's coarse hit areas grow toward 44px without taking from a neighbour
Per Cindy's 18:22 rule, an expansion never overlaps a neighbour's target: the flat 8px expansion (first match in DOM order on overlap) gives way to the shared hit area, resolveHitTarget (#8635), as the tracker's resolveTarget under a coarse pointer: each action's area grows toward 44px, each side capped at half the gap. The driver passes resolveTarget through; a fine pointer keeps the actions' own bounds. utils/hitArea.ts and its test are carried verbatim from #8635 (e297a6b) until it lands; this branch takes #8635 instead once it is on main.
1 parent a9dd5fe commit 2011ce5

5 files changed

Lines changed: 834 additions & 22 deletions

File tree

‎packages/core/src/hooks/useActionGroupTracking.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {UIKIT_PRESS} from '../motion/uikit/gestures';
5757
import {
5858
createActionGroupTracker,
5959
type ActionGroupTracker,
60+
type ActionGroupTrackerOptions,
6061
} from './actionGroupTracker';
6162
import {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';
6263

@@ -93,6 +94,12 @@ export interface ActionGroupTrackingOptions {
9394
manageStyle?: boolean;
9495
/** Runs the action under the finger at the lift. @default its own click */
9596
onActivate?: (item: HTMLElement) => void;
97+
/**
98+
* Which action a point is on, from the rects measured at press start
99+
* (the tracker's `resolveTarget`), read at each press. @default the
100+
* action whose rect, grown by `highlightExpansion`, holds the point
101+
*/
102+
resolveTarget?: ActionGroupTrackerOptions['resolveTarget'];
96103
}
97104

98105
const PRESS = UIKIT_PRESS;
@@ -120,6 +127,7 @@ export function useActionGroupTracking(
120127
itemSelector: optionsRef.current.itemSelector,
121128
highlightExpansion: optionsRef.current.highlightExpansion,
122129
onActivate: optionsRef.current.onActivate,
130+
resolveTarget: optionsRef.current.resolveTarget,
123131
}));
124132
const tracker = trackerRef.current;
125133
const isEnabled = options.isEnabled ?? true;

‎packages/core/src/hooks/useSiblingActionTracking.test.tsx‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import {Button} from '../Button';
1818
import {TextInput} from '../TextInput';
1919
import {Toolbar} from '../Toolbar';
2020
import {coarsePrimaryPointer} from '../gestures/__tests__/pointerQuery';
21-
import {
22-
COARSE_HIT_EXPANSION,
23-
SIBLING_ACTION_SELECTOR,
24-
} from './useSiblingActionTracking';
21+
import {SIBLING_ACTION_SELECTOR} from './useSiblingActionTracking';
2522

2623
interface Point {
2724
x: number;
@@ -158,14 +155,26 @@ describe('useSiblingActionTracking', () => {
158155
]);
159156
});
160157

161-
it('reaches 44px under a coarse pointer: a press just outside a button lights it (FR5)', () => {
162-
const {cut, onCut} = mountToolbar();
163-
const f = finger(cut);
164-
const justOutside = {x: -COARSE_HIT_EXPANSION + 2, y: 16};
165-
f.down(justOutside);
158+
it('grows each button toward 44px under a coarse pointer without taking from its neighbour (FR5)', () => {
159+
const {cut, copy, onCut, onCopy} = mountToolbar();
160+
// Cut is 32px wide at 0, Copy at 40: Cut reaches 6px out on its open
161+
// side, and the 8px gap splits at its middle.
162+
const outside = {x: -4, y: 16};
163+
const first = finger(cut);
164+
first.down(outside);
166165
expect(paintOf(cut)).toBe('on');
167-
f.up(justOutside);
166+
first.up(outside);
168167
expect(onCut).toHaveBeenCalledTimes(1);
168+
const nearCut = {x: 35, y: 16};
169+
const f = finger(cut);
170+
f.down(nearCut);
171+
expect(paintOf(cut)).toBe('on');
172+
expect(paintOf(copy)).toBeNull();
173+
f.move({x: 37, y: 16});
174+
expect(paintOf(cut)).toBeNull();
175+
expect(paintOf(copy)).toBe('on');
176+
f.up({x: 37, y: 16});
177+
expect(onCopy).toHaveBeenCalledTimes(1);
169178
});
170179

171180
it("tracks a Banner's end area only when it holds two or more actions", () => {

‎packages/core/src/hooks/useSiblingActionTracking.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@
2929
* press.
3030
* - Only a row of two or more actions tracks (family:action-groups adoption
3131
* table); a single action keeps the browser's own click.
32-
* - Under a coarse pointer each action's hit area grows to at least 44px
33-
* (FR5): 8px past a 28px Button on every side. Nothing changes visually,
34-
* and a fine pointer keeps the actions' own bounds.
32+
* - Under a coarse pointer each action's hit area grows toward 44px (FR5),
33+
* each side capped at half the gap to its neighbour so no area takes from
34+
* another (utils/hitArea.ts). Nothing changes visually, and a fine pointer
35+
* keeps the actions' own bounds.
3536
*
3637
* SYNC: When modified, update useSiblingActionTracking.test.tsx
3738
*/
3839

3940
import type {RefObject} from 'react';
4041
import {stableClassName} from '../naming';
4142
import {COARSE_POINTER_QUERY} from '../utils/coarsePointer';
43+
import {resolveHitTarget} from '../utils/hitArea';
44+
import type {ActionGroupTarget} from './actionGroupTracker';
4245
import {useActionGroupTracking} from './useActionGroupTracking';
4346
import {useMediaQuery} from './useMediaQuery';
4447

@@ -55,14 +58,18 @@ export const SIBLING_ACTION_SELECTOR = `${BUTTON}:not(:scope [popover] *), ${TOG
5558
const NOT_THE_ROW =
5659
'input, textarea, select, [contenteditable]:not([contenteditable="false"]), [role="combobox"], [popover]';
5760

58-
/** The smallest hit target a coarse pointer gets, px (family:action-groups FR5). */
59-
const COARSE_TARGET = 44;
60-
61-
/** The smallest action in a row: a small Button, px. */
62-
const SMALLEST_ACTION = 28;
63-
64-
/** How far past each action a coarse pointer still hits it, px. */
65-
export const COARSE_HIT_EXPANSION = (COARSE_TARGET - SMALLEST_ACTION) / 2;
61+
/**
62+
* Which action a coarse pointer's point is on: each action's hit area grows
63+
* toward 44 px, each side capped at half the gap to its neighbour, so no area
64+
* takes from another (utils/hitArea.ts, family:action-groups FR5).
65+
*/
66+
function coarseTarget(
67+
x: number,
68+
y: number,
69+
actions: ReadonlyArray<ActionGroupTarget>,
70+
): HTMLElement | null {
71+
return actions[resolveHitTarget(x, y, actions)]?.element ?? null;
72+
}
6673

6774
export interface SiblingActionTrackingOptions {
6875
/** Off, nothing is attached. @default true */
@@ -96,7 +103,9 @@ export function useSiblingActionTracking(
96103
itemSelector: SIBLING_ACTION_SELECTOR,
97104
// A plain row has no measured onset or margin: the action lands lit.
98105
highlightOnsetMs: 0,
99-
highlightExpansion: isCoarse ? COARSE_HIT_EXPANSION : 0,
106+
highlightExpansion: 0,
107+
// A fine pointer keeps the actions' own bounds.
108+
resolveTarget: isCoarse ? coarseTarget : undefined,
100109
pointerTypes: ['touch', 'pen', 'mouse'],
101110
shouldTrack: target => shouldTrackRow(ref.current, target),
102111
isInert,

0 commit comments

Comments
 (0)