Skip to content

Commit a12f6f1

Browse files
committed
fix(AlertDialog): a mouse press on the actions acts natively again
The action group's tracking took every pointer on every presentation, so a desktop mouse press on Cancel released on Delete ran Delete. Under the touch presentation a finger's or a pen's press keeps sliding across the actions; a mouse press acts as the platform's native button does, on the action it began on, released over it.
1 parent fc68123 commit a12f6f1

9 files changed

Lines changed: 102 additions & 110 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+
[fix] AlertDialog's actions act as native buttons under a mouse again: a press runs the action it began on, released over that action, and a press slid from one action to the other runs nothing. Under the touch presentation a finger's or a pen's press still slides across the actions and runs the one it lifts on. On a desktop the actions carry no tracking marker, as before the action group shipped.
6+
7+
@vjeux

‎docs/families/action-groups.md‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ Selector's and MultiSelector's options FR1–FR5
131131

132132
## Cross-component invariants
133133

134-
- **FR1 — The lift decides.** In a member, a press on an action that slides
135-
across its siblings acts on the action the pointer lifts on, through that
136-
action's own activation; a press that never leaves its action acts on it.
137-
One gesture acts at most once (`spec:AST-094` FR26). After a slide, focus does what
138-
a click on the lifted action does.
134+
- **FR1 — The lift decides.** Under the touch presentation (`spec:AST-094`
135+
FR13), in a member, a press on an action that slides across its siblings
136+
acts on the action the pointer lifts on, through that action's own
137+
activation; a press that never leaves its action acts on it. One gesture
138+
acts at most once (`spec:AST-094` FR26). After a slide, focus does what a
139+
click on the lifted action does. A mouse press acts as the platform's
140+
native button does: on the action it began on, released over that action.
139141
- **FR2 — The highlight follows the pointer.** While the pointer is held, the
140142
enabled action under it is highlighted, at most one at a time, and nothing
141143
is highlighted over a disabled action, a gap, or outside the group
@@ -205,6 +207,16 @@ they are outside the family.
205207
- `spec:AST-094/DEC-17` — every group of sibling actions tracks a held
206208
pointer the same way.
207209

210+
### DEC-1 — The slide across actions is for touch only
211+
212+
**Decider:** `cixzhang`, `2026-11-03`
213+
214+
The slide-across press runs under the touch presentation only. A desktop
215+
mouse press behaves as a native button does: only the pressed action
216+
activates, with no drag across the others.
217+
218+
Rejected: every pointer.
219+
208220
## Open questions
209221

210222
None.

‎docs/specs/AST-094-touch-presentations/spec.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ under a finger, and a mouse follows `module:DropdownMenu/useMenuPress` FR3 and
596596
selection and native drag, while a trackpad's horizontal scroll swipes a
597597
row (`spec:AST-057` AR2, DEC-7); a
598598
pinch under a pen; the screen-edge pan under a mouse, a trackpad, or a pen;
599-
and the 44 px coarse-pointer touch target, which stays coarse-only and never overlaps a
599+
the slide across an action group under a mouse (`family:action-groups`
600+
FR1); and the 44 px coarse-pointer touch target, which stays coarse-only and never overlaps a
600601
neighbor's target. On the web, a pan takes a trackpad's two-finger scroll
601602
where its record allows it, and never a mouse wheel's notches. A scroll is a
602603
trackpad's only when it carries Chromium's and WebKit's trackpad signature:
@@ -725,7 +726,7 @@ under a finger, and a mouse follows `module:DropdownMenu/useMenuPress` FR3 and
725726
FR11's profiles under every pointer, the fine-pointer profile included.
726727
- Every `family:action-groups` member, as its membership rule lists them:
727728
a press that slides across sibling actions acts on the action it lifts on
728-
(FR26–FR28), under every pointer.
729+
(FR26–FR28), under the touch presentation (`family:action-groups` FR1).
729730
- Every component under a coarse pointer: no box grows for touch, and a
730731
touch target reaches 44 px only through an invisible hit area clamped by
731732
its neighbors, unless a component or module record sets its own (FR42).

‎docs/specs/components/AlertDialog/AlertDialog.spec.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ system_specs:
5050
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
5151
| Public contract | `AlertDialog`, `AlertDialogProps`, and `useImperativeAlertDialog` are exported from `@astryxdesign/core/AlertDialog`; `title`, `description`, `actionLabel`, `onAction`, and `onOpenChange` are required with `isOpen`, plus cancel label, action variant, loading, width, and an inline preview mode. |
5252
| Behavior | A modal confirmation that interrupts: it opens through the native dialog, cannot be dismissed by a click outside, closes on Escape or Cancel through `onOpenChange(false)`, and runs `onAction` on the action button. |
53-
| End-user impact | A keyboard or screen-reader user is told a decision is needed (the title and description are announced), lands on Cancel, and cannot lose the dialog by clicking past it. On a touch screen the alert scales in and fades out as iOS's does and ignores taps while it enters (FR6, FR7), and on a phone it is 320 px wide (FR9); under every pointer, mouse included, a press that slides from Cancel to the action runs the action it lifts on (FR8). |
53+
| End-user impact | A keyboard or screen-reader user is told a decision is needed (the title and description are announced), lands on Cancel, and cannot lose the dialog by clicking past it. On a touch screen the alert scales in and fades out as iOS's does and ignores taps while it enters (FR6, FR7), and on a phone it is 320 px wide (FR9); on a touch screen a press slid from Cancel to the action runs the lifted action; a mouse's press acts natively (FR8). |
5454
| Builder impact | None. |
5555
| Compatibility/readiness | FR1–FR5, FR8 and AR1 record shipped behavior, apart from AR1's Tab wrap. FR6, FR7 and FR9 are requirements not shipped yet. Each gap is listed under Current-state impact. |
5656
| Review checks | Reject a modal AlertDialog without `role="alertdialog"`, a title or description not linked by id, initial focus on the destructive action, or a backdrop click that dismisses it. |
@@ -67,8 +67,9 @@ confirmation without assembling it.
6767

6868
## Compatibility and migration
6969

70-
- Released default preserved: `no` — FR8 changes action activation under a
71-
slide; shipping FR6, FR7 and FR9 changes the touch presentation and the
70+
- Released default preserved: `no` — under the touch presentation FR8
71+
changes action activation under a slide; a mouse press keeps the native
72+
button's; shipping FR6, FR7 and FR9 changes the touch presentation and the
7273
phone width
7374
- Compatibility class: nonbreaking behavior change; no public API, DOM, or
7475
target change
@@ -130,7 +131,7 @@ Consumer migration instructions belong in consumer docs and release notes.
130131
| FR5 | `useImperativeAlertDialog` returns `show`, `hide`, and the element to render, and owns `isOpen`/`onOpenChange` for its caller. | shipped source and focused tests |
131132
| FR6 | Under a touch presentation (`spec:AST-094` FR13), a modal AlertDialog presents by scaling from 1.2 to 1 with its opacity and its backdrop's dimming rising from 0 to 1 on the motion role `springs.alertPresent`, started at the browser's commit, with the larger start kept inside the viewport; it dismisses by a fade alone on `springs.alertDismiss` and closes at the fade's end; a close during the presentation, or a reopen during the dismissal, springs from where it is. The roles are internal, with UIKit's measured values at `tempo` 1 and `'standard'`, and follow the theme's motion knobs (`spec:AST-094` FR4, DEC-15). Under Reduce Motion both are the shared cross-fade (`design:reduced-motion` DR1–DR3). A fine primary pointer keeps today's motion (`spec:AST-094` FR13 and its Non-goals). Implementation gap: not shipped yet (Current-state impact). | proposed from measured iOS 26.2 behavior |
132133
| FR7 | Under a touch presentation, pointer input to the alert is held while it enters (`spec:AST-094` FR35); keyboard and assistive-technology input are never held, and the entrance never makes the content inert. While the alert leaves, its content is inert for the dismissal fade. The hold's timing stays internal (`spec:AST-002` FR3). Implementation gap: not shipped yet (Current-state impact). | `spec:AST-094` FR35; owner decision (DEC-1) |
133-
| FR8 | AlertDialog's actions are an action group (`family:action-groups`): a press that slides across them runs the action it lifts on, and a lift outside them runs nothing, under every pointer; keyboard and assistive-technology behavior is unchanged. | `family:action-groups`; `spec:AST-094` DEC-17; DEC-3 |
134+
| FR8 | AlertDialog's actions are an action group (`family:action-groups`): under the touch presentation (`spec:AST-094` FR13), a press that slides across them runs the action it lifts on, and a lift outside them runs nothing; a mouse press acts as the platform's native button does; keyboard and assistive-technology behavior is unchanged. | `family:action-groups`; `spec:AST-094` DEC-17; DEC-3 |
134135
| FR9 | On a phone, a compact window (`spec:AST-012` FR9: narrower than `md` or shorter than 500 px) under a coarse primary pointer, the alert is 320 px wide in every theme, as iOS's is; no theme role sets it. A caller's explicit `width` still wins there (`architecture:public-component-api` INV5), and Dialog's viewport clamp still applies on a screen narrower than the alert. Elsewhere it keeps today's width. Implementation gap: not shipped yet (Current-state impact). | owner decision (DEC-2) |
135136

136137
### Allowed variation

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,27 @@ describe('AlertDialog action tracking', () => {
540540
element.getBoundingClientRect = () => rect;
541541
}
542542

543+
function mouse(
544+
type: 'pointerdown' | 'pointermove' | 'pointerup',
545+
target: Element,
546+
point: {x: number; y: number},
547+
): void {
548+
touchClock += 16;
549+
const event = new PointerEvent(type, {
550+
bubbles: true,
551+
cancelable: true,
552+
pointerId: 1,
553+
pointerType: 'mouse',
554+
isPrimary: true,
555+
button: 0,
556+
buttons: type === 'pointerup' ? 0 : 1,
557+
clientX: point.x,
558+
clientY: point.y,
559+
});
560+
Object.defineProperty(event, 'timeStamp', {value: touchClock});
561+
target.dispatchEvent(event);
562+
}
563+
543564
function renderOpen(props: {isInline?: boolean; coarse?: boolean} = {}) {
544565
const isCoarse = props.coarse ?? true;
545566
stubAlertDialogMedia({
@@ -591,6 +612,24 @@ describe('AlertDialog action tracking', () => {
591612
}
592613
});
593614

615+
it("tracks nothing under a fine primary pointer: a desktop press stays the native button's (family:action-groups FR1)", () => {
616+
const {cancel, action} = renderOpen({coarse: false});
617+
for (const button of [cancel, action]) {
618+
expect(isTrackedByGroup(button)).toBe(false);
619+
expect(button).toHaveAttribute('data-astryx-pressable');
620+
}
621+
});
622+
623+
it('leaves a mouse press to the native button under the touch presentation: one slid from the action to Cancel runs nothing (family:action-groups FR1)', () => {
624+
const {onOpenChange, onAction, cancel, action} = renderOpen();
625+
mouse('pointerdown', action, {x: 60, y: 116});
626+
mouse('pointermove', action, {x: 60, y: 156});
627+
expect(cancel).not.toHaveAttribute('data-astryx-press', 'on');
628+
mouse('pointerup', cancel, {x: 60, y: 156});
629+
expect(onOpenChange).not.toHaveBeenCalled();
630+
expect(onAction).not.toHaveBeenCalled();
631+
});
632+
594633
it('runs the action a finger lifts on: from the action to Cancel cancels, from Cancel to the action runs it', () => {
595634
const {onOpenChange, onAction, cancel, action} = renderOpen();
596635
let id = touchId++;

‎packages/core/src/AlertDialog/AlertDialog.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type {BaseProps} from '../BaseProps';
3434
import {mergeProps} from '../utils/mergeProps';
3535
import {themeProps} from '../utils/themeProps';
3636
import {useMediaQuery} from '../hooks/useMediaQuery';
37+
import {useTouchPresentation} from '../utils/touchPresentation';
3738
import {
3839
registerEnglishFallback,
3940
useComponentTranslator,
@@ -46,6 +47,9 @@ import {pressGroupItemProps} from '../privateAttributes/pressGroupItem.stylex';
4647

4748
registerEnglishFallback(english);
4849

50+
/** The pointers a press slides with across the actions. */
51+
const SLIDING_POINTERS = ['touch', 'pen'] as const;
52+
4953
const SMALL_SCREEN_QUERY = '(max-width: 640px)';
5054

5155
const styles = stylex.create({
@@ -193,12 +197,17 @@ export function AlertDialog({
193197
// Each action carries the press-group marker from its first render, so the
194198
// tracker is its only painter.
195199
const actionsRef = useRef<HTMLElement>(null);
196-
const isTracking = isOpen && isInline !== true;
200+
// Only under the touch presentation does a press slide across the
201+
// actions. A desktop press stays the native button's.
202+
const {isTouch} = useTouchPresentation();
203+
const isTracking = isOpen && isInline !== true && isTouch;
197204
useActionGroupTracking(actionsRef, {
198205
// The actions row holds only the two buttons.
199206
itemSelector: 'button',
200207
highlightOnsetMs: alertController.actions.highlightOnsetMs,
201208
highlightExpansion: alertController.actions.highlightExpansion,
209+
// A mouse press acts as a native button's under any presentation.
210+
pointerTypes: SLIDING_POINTERS,
202211
isEnabled: isTracking,
203212
});
204213
const actionTrackingProps = isTracking ? pressGroupItemProps : undefined;

0 commit comments

Comments
 (0)