Skip to content

Commit 3d225c3

Browse files
cixzhangvjeux
andauthored
feat(core): under a finger a pressable highlights at touch-down outside scroll views (#9765)
feat(core): under a finger a pressable highlights at touch-down outside scroll views A touch on a pressable that is not inside a scroll view paints its press in the frame the finger lands, as a UIControl does; inside a scroll view the content-touch delay still applies. The press controller and the gesture core's scroll probe share one scroll-view test (utils/scrollView). The WebKit interaction proofs now run when that module changes. Co-authored-by: Cindy Zhang <cindyxz@meta.com> Co-authored-by: Christopher Chedeau <vjeuxx@gmail.com>
1 parent 54166ff commit 3d225c3

15 files changed

Lines changed: 731 additions & 107 deletions
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] Under a finger, a pressable (a button, card, link, list row or any other surface) outside a scroll view now highlights in the frame the finger lands, as UIKit's controls do, instead of after a 150 ms delay. Inside a scroll view it still waits that delay, so a flick paints nothing, and a scroll that takes a held press cancels it with no fade. A page that scrolls counts as a scroll view, so on a page taller than the screen a press still waits; a control in a fixed bar, or on a page that fits, highlights at once. A mouse on a desktop keeps `:active`.
6+
7+
@vjeux

‎.github/scripts/ci-interaction-webkit.test.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ describe('WebKit interaction proof routing', () => {
255255
'packages/core/src/hooks/useIsomorphicLayoutEffect.ts',
256256
'packages/core/src/hooks/useAttachment.ts',
257257
'packages/core/src/utils/sharedResizeObserver.ts',
258+
'packages/core/src/utils/scrollView.ts',
258259
'packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts',
259260
'packages/core/src/hooks/__tests__/pagerBundle.ts',
260261
'internal/interaction-harness/src/webInput.ts',

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,7 @@ jobs:
25262526
id: scope
25272527
uses: ./.test-scope/.github/actions/test-scope
25282528
with:
2529-
paths: '^(packages/core/src/gestures/|packages/core/src/motion/|packages/core/src/internal/touch|packages/core/src/utils/(press|touch|primaryClick|isApplePlatform|flatTree|inputStream|clickGuard|selectionLock|coarsePointer|sharedResizeObserver)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/Layer/inputHold\.ts$|packages/core/src/hooks/(useMenuPress|menuPress|useLongPress|usePressFeedback|isRtlElement|useIsomorphicLayoutEffect|useAttachment|usePager|__tests__/(usePager|pagerBundle))|internal/interaction-harness/|internal/a11y-spec/|playwright\.interaction\.config\.ts$|packages/themes/[^/]+/src/|apps/storybook/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$|\.github/scripts/(interaction-legs|a11y-pr-contracts)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/interaction-durations\.json$|\.github/actions/test-scope/)'
2529+
paths: '^(packages/core/src/gestures/|packages/core/src/motion/|packages/core/src/internal/touch|packages/core/src/utils/(press|touch|primaryClick|isApplePlatform|flatTree|inputStream|clickGuard|selectionLock|coarsePointer|sharedResizeObserver|scrollView)|packages/core/src/privateAttributes/(hapticSwitch|reducedMotion)\.stylex\.ts$|packages/core/src/Layer/inputHold\.ts$|packages/core/src/hooks/(useMenuPress|menuPress|useLongPress|usePressFeedback|isRtlElement|useIsomorphicLayoutEffect|useAttachment|usePager|__tests__/(usePager|pagerBundle))|internal/interaction-harness/|internal/a11y-spec/|playwright\.interaction\.config\.ts$|packages/themes/[^/]+/src/|apps/storybook/|\.github/workflows/ci\.yml$|package\.json$|pnpm-lock\.yaml$|\.github/scripts/(interaction-legs|a11y-pr-contracts)\.mjs$|scripts/lib/duration-split\.mjs$|\.github/interaction-durations\.json$|\.github/actions/test-scope/)'
25302530
outside-pull-request: skip
25312531
requires-head-file: playwright.interaction.config.ts
25322532

‎apps/storybook/stories/PressFeedback.stories.tsx‎

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import {VStack} from '@astryxdesign/core/Layout';
2626
* View these with a coarse pointer: in Chromium, open DevTools, toggle the
2727
* device toolbar (a phone preset), and use the touch cursor; or open Storybook
2828
* on a phone. Under a finger the bare `:active` arm is dropped and the press
29-
* follows the clocks a native list uses: nothing paints for 150 ms; a held
30-
* press then paints the full pressed overlay on the next frame; travelling
31-
* 10 px, or a scroll claiming the gesture, cancels it with no fade and nothing
32-
* repaints until a new touch; a tap shorter than the delay paints at the lift;
33-
* the release fades over 200 ms. A mouse keeps `:active`.
29+
* follows UIKit. A surface highlights in the frame the finger lands, or
30+
* 150 ms later inside a scroller, where a flick paints nothing; travelling
31+
* 10 px, or the browser taking the touch to scroll, cancels it with no fade;
32+
* a tap shorter than the delay paints at the lift; the lift fades it out. A
33+
* mouse keeps `:active` on a desktop.
3434
*/
3535
const meta: Meta = {
3636
title: 'Core/Press feedback (touch)',
@@ -39,7 +39,7 @@ const meta: Meta = {
3939
docs: {
4040
description: {
4141
component:
42-
'The touch press model on every pressable surface. View with a coarse pointer (DevTools device toolbar, or a phone). Under a finger the bare `:active` arm is dropped and one document-level controller writes `data-astryx-press="on"` once a press is believed (150 ms, no travel, no scroll) and `data-astryx-press="fading"` for the 200 ms release; a scroll or 10 px of travel cancels with no fade, and nothing repaints until a new touch. A mouse keeps `:active`. Scroll the list stories with a finger: no row paints while the list moves.',
42+
'The touch press model on every pressable surface. View with a coarse pointer (DevTools device toolbar, or a phone). Under a finger the bare `:active` arm is dropped and one document-level controller writes `data-astryx-press="on"` while a press is held and `data-astryx-press="fading"` for the release. A surface highlights in the frame the finger lands (150 ms later inside a scroller) and fades at the lift; 10 px of travel or a scroll claiming the touch cancels it with no fade. A mouse keeps `:active` on a desktop. Scroll the list stories with a finger: nothing paints while the list moves.',
4343
},
4444
},
4545
},
@@ -48,12 +48,12 @@ const meta: Meta = {
4848
export default meta;
4949
type Story = StoryObj;
5050

51-
const touchNote = (what: string) =>
52-
`${what} Hold: paints after 150 ms. Tap: paints at the lift. Drag or scroll: never paints, and stays dark until the finger lifts and lands again.`;
51+
const controlNote = (what: string) =>
52+
`${what} Touch: paints in the frame the finger lands. Lift: fades out. A scroll that takes the touch: the paint goes at once, with no fade and no click.`;
5353

5454
export const Buttons: Story = {
5555
parameters: {
56-
docs: {description: {story: touchNote('Buttons under a finger.')}},
56+
docs: {description: {story: controlNote('Buttons under a finger.')}},
5757
},
5858
render: () => (
5959
<VStack gap={3}>
@@ -70,9 +70,8 @@ export const Rows: Story = {
7070
parameters: {
7171
docs: {
7272
description: {
73-
story: touchNote(
74-
'Item rows, a menu, and a clickable card. The list scrolls: flick it and no row paints; stop it with a finger and that touch is a brake, not a press.',
75-
),
73+
story:
74+
'Item rows, a menu, and a clickable card. The rows sit in a scroller, so a held row paints after 150 ms, a tap paints at the lift, and a drag or scroll never paints; the card, outside it, paints in the frame the finger lands. Flick the list and no row paints.',
7675
},
7776
},
7877
},
@@ -113,7 +112,7 @@ export const Controls: Story = {
113112
parameters: {
114113
docs: {
115114
description: {
116-
story: touchNote(
115+
story: controlNote(
117116
'The eight components that gained a pressed state, under a finger.',
118117
),
119118
},
@@ -159,3 +158,30 @@ export const Controls: Story = {
159158
);
160159
},
161160
};
161+
162+
export const ButtonsInScroller: Story = {
163+
parameters: {
164+
docs: {
165+
description: {
166+
story:
167+
'Buttons in a scrolling list, under a finger: a held button paints 150 ms after the finger lands (UIScrollView.delaysContentTouches); a flick scrolls the list and paints nothing; a scroll that starts after the button painted takes the touch, and the paint goes at once with no fade and no click.',
168+
},
169+
},
170+
},
171+
render: () => (
172+
<div
173+
data-testid="button-scroller"
174+
style={{height: 240, overflowY: 'auto', border: '1px solid transparent'}}>
175+
<VStack gap={3}>
176+
{Array.from({length: 16}, (_, index) => (
177+
<Button
178+
key={index}
179+
label={`Action ${index + 1}`}
180+
variant="secondary"
181+
onClick={() => {}}
182+
/>
183+
))}
184+
</VStack>
185+
</div>
186+
),
187+
};

0 commit comments

Comments
 (0)