Skip to content

feat(core): change details (source, cancel) on every value callback - #607

Merged
lorant-one merged 3 commits into
previewfrom
feat/control-change-details
Nov 28, 2026
Merged

lorant-one merged 3 commits into
previewfrom
feat/control-change-details

Conversation

@lorant-one

Copy link
Copy Markdown
Member

Requested by Lorant · project thread

Step 1 of making Once UI agent-operable (study: UI SDK vs Once UI). Before core can let an agent drive a live page, every control has to report who changed it and let the app refuse the change.

What changes

  • Every onXChange on the shared value contract (useControllableState) now passes a second argument, details: ChangeDetails: source (pointer, keyboard, agent, programmatic), the DOM event when one was passed, and cancel(). A canceled change leaves an uncontrolled component as it was.
  • The controls that keep their own state get the same thing: Input, Textarea (an uncontrolled field puts its text back), NumberInput, OTPInput, ColorInput, Tabs, DatePicker (single and range) and the range Slider.
  • withChangeSource("agent", fn) (exported) marks the changes fn makes. The bridge in step 2 wraps its actions in it, and apps can use it to pass a press's source on after an await.
  • The source comes from the event the setter got, then from window.event. A relayed input.click() or a checkbox change falls back to the last pointerdown or keydown seen in the capture phase within the last second.
  • SegmentedControl keeps its event second and passes details third, so studio's SetFont keeps working.
  • details is optional in the prop types, so a wrapper that calls the callback with the value alone still compiles.

Compatibility

This is additive at runtime. The one thing that shows: a test asserting toHaveBeenCalledWith(value) on one of these callbacks now sees the extra argument. That's why 38 test files change. They only gained a changeDetails matcher (src/test/changeDetails.ts) or .slice(0, 1) on mock.calls. The CHANGELOG says so under Unreleased, so this goes out in a minor, not a patch. Generated ai/ files are left for the release regeneration, as AGENTS.md asks.

Checks

  • tsc --noEmit: 0 errors
  • pnpm build: passes
  • vitest run: 350 files, 4,913 tests pass, including the new change-details.test.tsx (pointer vs keyboard, cancel on Switch, Input and Tabs, agent source, SegmentedControl's argument order)
  • Biome reports no new findings on the touched files

Generated by Claude Code

Every onXChange on the shared value contract, and the controls that keep
their own state (Input, Textarea, NumberInput, OTPInput, ColorInput, Tabs,
DatePicker, RangeSlider), now pass ChangeDetails after the value: source
(pointer, keyboard, agent, programmatic), the DOM event when there is one,
and cancel(), which keeps an uncontrolled component as it was.
withChangeSource("agent", fn) marks an assistant's changes. SegmentedControl
keeps its event second and passes details third.

First step toward an agent bridge in core (snapshot, act, query).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtyAjxtXFsms7HWCd1w
useControllableState now reads changeDetails, so it moves to core's
internal/ and fx copies both, held to core's by the parity test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtyAjxtXFsms7HWCd1w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants