Skip to content

feat(SegmentedControl): a drag that drifts off keeps choosing - #10978

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:segmented-drift-keeps-choosing
Nov 11, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:segmented-drift-keeps-choosing

Conversation

@vjeux

@vjeux vjeux commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Primary intent

Carry out a design-review decision on a held press that leaves a SegmentedControl. Not a bug fix: it changes the interaction model by decision. Not specification-only: the code ships with its records.

User or maintainer impact

Today a drag that leaves the control vertically selects nothing at the lift, while the highlight keeps following the finger. Now the press keeps choosing by its horizontal position, however far it drifts, and the lift commits that segment. A mouse or a pen drags the same way. Past either end, the end segment counts.

Only a cancel commits nothing: pointercancel (a system gesture, or a page scroll that claims the touch first) or Escape. The highlight then returns to the selected segment at once. During a drag from another segment, the segment the lift would commit shows the press paint.

Accessibility contract consequence

The shared radio-group contract's required aborted-press check releases 200 px away and expects no change. A release straight away now chooses by position, so SegmentedControl's options take that check through their own abort. The press slides off the control in the current choice's column and lifts there. WCAG 2.5.2 is met by that abort, Escape, and undo, which the contract's pointer round trip covers.

Problem and solution fit

  • The shared tracker (actionGroupTracker) gains tracksAlong: a one-axis group counts a held pointer on its center line, clamped to its ends. Escape cancels such a press, and onCancel tells the owner.
  • paintsHighlight also takes a function, so SegmentedControl paints only the segment a drag from another segment would commit.
  • SegmentedControl passes 'x'. On Escape it cuts the press paint and returns the lens.

Authority

  • architecture:interaction-modality INV14 (new): a one-axis group that chooses tracks along its axis. Button groups and menus keep their slide-off rule.
  • spec:AST-020 DEC-6 (new) quotes the design review, covers SegmentedControl only, and replaces DEC-5's SegmentedControl clause. After design review confirmed it for a mouse and a pen, the spec owner approved it at fde848a (/approve-spec).
  • component:SegmentedControl FR3 lists the cancel cases, and FR13 follows it.
  • UISegmentedControl (iOS 26.2 simulator) never cancels a drag from the selected segment on a drift. A press from another segment cancels about 70 pt off the control.
  • Owner-gated (/approve-spec <head sha>): all three records.

Writing rubric results

INV14, DEC-6, FR9's sentence, FR3 and FR13: R1–R6 none. DEC-6 quotes the design review verbatim, and its next sentence states the meaning.

Scope

  • This PR has one primary intent.
  • Independently removable deltas were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

On a phone, open SegmentedControl in the preview. Press the selected segment, slide to another one, drag well below the control and lift: that segment is selected. Press, drag, then press Escape: nothing changes.

Check (this head, 3bc5fe8: the change plus a merge of main 4236e88) Result
The touch-target spec's drag past a segment's band now expects the drift rule, claimed sideways first; on main's build fails in Chromium and WebKit: nothing is selected
Escape, then a release on the starting segment after a hold or a drag away and back, past the guard's window: two mouse cases, on 879aac8's build both fail in Chromium and WebKit: the browser's click selected it
SegmentedControl interaction and touch-target specs at this head, 1 worker Chromium 60/60; WebKit 56 passed, 4 skipped
Radio-group accessibility contract at this head, Chromium, 1 worker 31/31
At this head: pnpm lint:strict (CI's mode), core typecheck, check:knowledge, units (SegmentedControl, hooks, RadioList) pass: 0 lint errors, units 1318
At 879aac8, whose docs and records this head keeps: CLI suite (search goldens), core typecheck, check:knowledge, SegmentedControl units, public text pass: CLI 10587, units 160
The rows below ran at fbce128. Since then, only where Escape arms the click guard, and tests, have changed
Red first: this head's seven changed SegmentedControl cases, on main's build 7 of 7 fail in Chromium and WebKit, each on its intended assertion
The browser-cancel guard (Chromium only), on main's build passes: main already hands the surface back
Escape, then a lift on the segment the press began on (mouse), on the previous head's build fails: the browser's own click selected it
SegmentedControl interaction, 1 worker (CI's profile) Chromium 54/54; WebKit 50 passed, 4 skipped (Chromium-only traces and pen input)
Radio-group accessibility contract, Chromium, 1 worker 33/33; the aborted-press check passes on both operable segment states
Units: the tracker, SegmentedControl, RadioList, ButtonGroup, ToggleButton, AlertDialog, internal touch and Lab TabBar 1637 pass
Core typecheck, check:knowledge, specs:for --diff, changesets, public text pass

@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 10, 2026 8:17pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2026
@astracat-bot

astracat-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 10, 2026, 8:28 PM UTC

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 10, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 3bc5fe8

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
SegmentedControl 98.5 kB (+1.4 kB) · 6.9 kB CSS (0) — ✗ · ✓ · ✓
SegmentedControlItem 17.5 kB (0) · 4.3 kB CSS (0) — ✗ · ✓ · ✓
DateTimeInput 210.6 kB (+454 B) · 18.7 kB CSS (0) — — · — · —
12 more components
Component Size LoC Visual · A11y · RTL
lab/CommentThread 347.5 kB (+390 B) · 2.4 kB CSS (0) — — · — · —
lab/Comments 354.4 kB (+378 B) · 2.5 kB CSS (0) — — · — · —
AlertDialog 106.9 kB (+373 B) · 14.6 kB CSS (0) — — · — · —
lab/TabBar 81.6 kB (+358 B) · 1.8 kB CSS (0) — — · — · —
ButtonGroup 42.2 kB (+357 B) · 3.7 kB CSS (0) — — · — · —
ToggleButtonGroup 39.7 kB (+354 B) · 3.7 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 280.4 kB (+344 B) · 454 B CSS (0) — — · — · —
ToggleButton 87.9 kB (+334 B) · 10.1 kB CSS (0) — — · — · —
lab/Schedule 107.4 kB (+326 B) · 3.9 kB CSS (0) — — · — · —
RadioList 57.3 kB (0) · 7.3 kB CSS (0) — ✓ · ✓ · ✓
RadioListItem 68.4 kB (0) · 10.1 kB CSS (0) — ✓ · ✓ · ✓
lab/TabBarItem 3.9 kB (0) · 1.8 kB CSS (0) — — · — · —
Visual changes: 1 snapshot in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
SegmentedControl · Default (neutral, dark) before frame after frame diff frame

Package size: @astryxdesign/core 7.29 MB packed (+3.2 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 36 rows, core 36 rows; run pnpm api:report.

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval waits on an owner decision about the proposed SegmentedControl drift rule, and three changes are needed besides.

This pull request replaces the current rule that a press which slides off the control selects nothing (spec:AST-020 FR9 and DEC-5, component:SegmentedControl FR3 and FR13) with new, unapproved architecture:interaction-modality INV14, spec:AST-020 DEC-6 and FR3/FR13 text, and because it also changes what a mouse or trackpad does, the record should trace that decision for desktop input with the words and when and where they were given. An engineering owner records the decision by commenting /approve-spec <full head SHA> on the pull request, and the author may do so as an engineering owner.

Blocking findings:

  • Escape does not take back a press released on the segment it began on: in Chromium, a mouse press on List, then Escape, then release on List still selects List through the browser's own click, so the cancel path in useSegmentedTouchTracking.ts should take that click and a browser test should cover it.
  • The proposed records contradict themselves: DEC-6 says "DEC-5 stands for the controls it names" while DEC-5 still names SegmentedControl, and the SegmentedControl record's compatibility row, FR3 basis and FR12/FR13 verification row still say a lift outside the control selects nothing.
  • The Changeset is tagged [fix] and the title says fix(...) for what the description calls a decided behavior change, which spec:AST-017 FR5 does not count as a fix, so it needs a different tag and a note that mouse drags change too.

Not blocking: an Escape that takes back a press inside a Dialog, Drawer or BottomSheet also closes it, because the tracker never marks the key handled.

[Automated review]

Comment thread docs/specs/AST-020/spec.md Resolved
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec c3b4509

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 10, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the SegmentedControl drift rule now has engineering-owner approval at this head, but the change does not meet it everywhere yet.

  • Escape does not take back a press released on the segment it began on: in Chromium, a mouse press on List, then Escape, then release on List still selects List through the browser's own click, so the cancelled lift in useSegmentedTouchTracking.ts should take that click and a browser test should cover it.
  • spec:AST-020 DEC-6 says "DEC-5 stands for the controls it names" while DEC-5 still says SegmentedControl keeps slide-off cancelling, so DEC-6 should state that it replaces that clause.
  • The SegmentedControl record's compatibility row, FR3 basis and FR12/FR13 verification row still say a lift outside the control selects nothing, which contradicts the new FR13.
  • Miss: SegmentedControl.doc.mjs still tells builders, in all three of its descriptions, that letting go outside the control selects nothing.
  • The Changeset is tagged [fix] and the title says fix(...) for what the description calls a decided behavior change, which spec:AST-017 FR5 does not count as a fix, so it needs another tag and a note that mouse drags change too.

Not blocking: an Escape that takes back a press inside a Dialog, Drawer or BottomSheet also closes it, because the tracker never marks the key handled. The approval binds this exact head, so the fixed head needs a fresh /approve-spec.

[Automated review]

@vjeux
vjeux force-pushed the segmented-drift-keeps-choosing branch from c3b4509 to 879aac8 Compare November 10, 2026 16:43
@vjeux vjeux changed the title fix(SegmentedControl): a drag that drifts off keeps choosing feat(SegmentedControl): a drag that drifts off keeps choosing Nov 10, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 10, 2026
@vjeux

vjeux commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

On the latest review, at 879aac8: each inline point has its answer on its thread.

  • SegmentedControl.doc.mjs: all three descriptions now say a drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing.
  • Desktop input: DEC-6 states that the rule holds for a mouse and a pen as for a finger, with the date in its Decider line. Design review confirmed that scope, and the spec owner approved the rule at c3b4509 (/approve-spec). This head needs a fresh /approve-spec.

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 879aac8

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 10, 2026

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the drift rule itself is approved by an engineering owner for this head, and one fix remains before it can merge.

  • After Escape, a press released on the segment it began on more than 400 ms later, or after dragging away and back, still selects that segment, because the click guard armed at the key press (useSegmentedTouchTracking.ts:209-214) disarms itself after 400 ms; arm it at the cancelled press's lift as well, and add browser cases that hold past 400 ms and that drag back before release.

Two smaller points that do not block: during a mouse drag from an unselected segment both the origin and the segment the lift will commit look pressed, and the per-press lift-area measurement can no longer change a result. CI has not run on this draft head yet.

[Automated review]

@vjeux
vjeux force-pushed the segmented-drift-keeps-choosing branch from 879aac8 to fde848a Compare November 10, 2026 17:41
@vjeux

vjeux commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

At fde848a, on this review's two non-blocking notes:

  • The two pressed segments during a mouse drag from another segment: the starting segment keeps the browser's own :active look under a fine pointer. Changing it is a visual decision, outside this change.
  • The lift area measured on every press: it is one rectangle read and no longer changes the result. Removing it touches exported helpers and their tests, so it is better as its own cleanup.

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec fde848a

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet, because the pull request is a draft from a fork. Mark it ready for review, and a maintainer adds the ci:run label so CI runs.

The drift rule (INV14, DEC-6, FR3 and FR13) has an engineering owner's approval for this head. The Escape cancel now takes back a press at any hold: the new mouse cases fail on the previous head's build and pass here.

Non-blocking, for a follow-up:

  • During a mouse drag from another segment, two segments look pressed: the starting one (:active) and the one the lift will commit.
  • measureLiftArea and the outside branch of liftTargetAt no longer change a result. Two comments are flagged inline.

[Automated review]

/** The segments as the finger found them (disabled ones too). */
const segmentsRef = useRef<SegmentSpan[]>([]);
/** The lift area as the finger found it: a lift outside it cancels. */
/** The lift area as the finger found it. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: nothing decides a lift from this area any more. The tracker hands liftTargetAt a point on the control's center line, so its outside branch never runs, yet measureLiftArea still reads layout on every press (line 269). Consider removing the area, that read and the outside branch together, with the unit case that pins a null the tracker never produces. Until then, this doc only restates the name (INV29).

let lastX = 0;
let lastY = 0;
const fades = new Map<Element, ReturnType<typeof setTimeout>>();
// A one-axis group's box, read at the begin: the finger counts inside it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking (INV29): the finger counts on this box's center line, not inside it. Suggested: // Read at the begin. A one-axis group counts the finger on this box's center line.

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 10, 2026
@vjeux
vjeux marked this pull request as ready for review November 10, 2026 19:04
@vjeux
vjeux marked this pull request as draft November 10, 2026 19:34
A press on SegmentedControl that drifted off the control cancelled at
the lift, so a drag that left it vertically selected nothing while the
highlight kept following the finger. The shared action-group tracker
now tracks a one-axis group along its axis: a held pointer counts on
the group's center line, clamped to its ends, and the lift commits the
segment under its horizontal position. Escape or a browser cancel takes
the press back, and the highlight returns at once. During a drag from
another segment, the segment the lift would commit shows the press
paint.

interaction-modality INV14, a new AST-020 decision for one-axis
controls and SegmentedControl FR3 state the rule and its cancel cases.
SegmentedControl's options take the radio-group contract's
aborted-press check through their own abort: a return to the current
choice before the lift.
@vjeux
vjeux force-pushed the segmented-drift-keeps-choosing branch from fde848a to 3bc5fe8 Compare November 10, 2026 20:02
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 10, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 3bc5fe8

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 10, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet, because the pull request is a draft from a fork. Mark it ready for review, and a maintainer adds the ci:run label so CI runs.

The drift rule (INV14, DEC-6 with its FR9 sentence, FR3 and FR13) has an engineering owner's approval for this head, and the SegmentedControl interaction specs and the radio-group contract pass in Chromium here.

Non-blocking, for a follow-up:

  • measureLiftArea and the outside branch of liftTargetAt no longer change a result, yet the area is still measured on every press.
  • Miss: two unchanged comments still describe the old rule, SegmentedControl.tsx:331 and useSegmentedSelectionMotion.ts:410-411 ("A lift outside the control commits nothing").
  • During a mouse drag from another segment, two segments look pressed: the starting one (:active) and the one the lift will commit.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 10, 2026 20:46
github-actions Bot added a commit that referenced this pull request Nov 10, 2026
@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 10, 2026
@vjeux
vjeux marked this pull request as draft November 10, 2026 22:10
@vjeux
vjeux marked this pull request as ready for review November 10, 2026 22:10
@vjeux
vjeux marked this pull request as draft November 11, 2026 00:47
@vjeux
vjeux marked this pull request as ready for review November 11, 2026 00:47
github-actions Bot added a commit that referenced this pull request Nov 11, 2026
@cixzhang
cixzhang merged commit e01c68b into meta:main Nov 11, 2026
247 of 297 checks passed
@vjeux
vjeux deleted the segmented-drift-keeps-choosing branch November 11, 2026 01:32

@abdulkadirhassan0840-cmyk abdulkadirhassan0840-cmyk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍😍😍

@abdulkadirhassan0840-cmyk abdulkadirhassan0840-cmyk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

53387598

This branch was successfully deployed

1 active deployment
Preview — 3bc5fe87 Deployed Nov 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants