Repository navigation
Description
Part of the v3 roadmap — #2721
Phase 3 — Component contract · pairs with the controlled-state work in #2723
Problem
State-change emits carry a bare value. To know why something closed — Escape vs outside-press vs selection — users listen to scattered granular events (escapeKeyDown, pointerDownOutside, interactOutside, focusOutside) on content parts and call .preventDefault() there. "Close on Escape but not on outside-press", confirm-before-close, and dismissal analytics are all hand-rolled per family.
Drawer already ships the better contract: 'update:open': [value: boolean, details?: DrawerOpenChangeDetails] with a typed reason union ('swipe' | 'escape-key' | 'outside-press' | 'click' | 'cancel' | 'trigger-press' | 'close-press') — packages/core/src/Drawer/DrawerRoot.vue:12-23,52. Every other family emits a bare value.
Prior art: Base UI's every change handler is (value, eventDetails) where eventDetails = { reason, event, cancel(), allowPropagation(), … } with a per-component typed reason union.
Goal
- A shared
ChangeEventDetailsshape inshared/types.ts:{ reason, originalEvent?, cancel(), allowPropagation()? }, with per-family reason unions (Drawer's becomes the first instance, not a special case). - Thread reasons through
DismissableLayer/FocusScope/ trigger handlers so everyupdate:open(and value emits where it makes sense) carries details. details.cancel()prevents the state change while staying uncontrolled — replacing most@escapeKeyDown.prevent-style usage; decide whether the granular events survive as deprecated escape hatches.- Imperative APIs (handles, composables) surface as
reason: 'imperative-action'.
Investigation: pairing with Vue v-model
v-model sugar compiles to @update:x="$event => (x = $event)" — it consumes only the first argument, so a second details arg is invisible to v-model users (fine for writes, but the details are only reachable via an explicit extra listener). Before committing, evaluate:
- Second emit arg (Drawer's current pattern): zero breakage,
v-modelkeeps working, explicit@update:open="(v, d) => …"opts into details. Does an extra listener alongsidev-modelfire reliably in all cases (it should — same event)? - Parallel semantic event (
@open-change="(v, details) => …"next toupdate:open): keeps the model emit pristine, closer to Base UI naming, but duplicates every emit. - Details via state, not event: expose
lastChangeDetailson the family'suseX()composable / root slot props (feat: headless logic composables for every component #2723), sov-modelusers read the reason reactively without touching listeners. - Controlled-state primitive interplay: the shared controllable-state composable (part of the feat: headless logic composables for every component #2723 foundation) must forward details through its emit path so this lands once, not ~50 times; check
defineModelcompatibility (itssetpath has no channel for extra args).
Likely answer is a combination of 1 + 3, but the investigation should settle it with real SFC playground tests before the pattern is propagated.
Why it matters
It's the single highest-value additive API change available (Drawer already proved the ergonomics), it unblocks confirm-before-close and analytics use cases cleanly, and it must be designed before #2723 freezes the composable emit contracts.
Activity
[-]feat: `eventDetails` on state-change emits — typed reason + `cancel()`, `v-model` pairing investigation[/-][+][Feature]: `eventDetails` on state-change emits — typed reason + `cancel()`, `v-model` pairing investigation[/+]zernonia commentedon Sep 4, 2026
Proposal for decision
Drafted against the
v3head so the emit channel can be settled before #2723 freezes more composable signatures. It also covers a case the investigation list above misses:cancel()ordering underv-model. Recommendations are marked; amend freely.1. Recommendation
Adopt option 1 (second emit arg, Drawer's existing shape at
Drawer/DrawerRoot.vue:52) for reporting, option 3 (lastChangeDetailsonuseX()and root slot props) for reading back, and implement both once via option 4: a newshared/useControllableState.tsreplacing the per-rootuseVModelcall. For cancellation, use a cancellable pre-change eventbeforeUpdate:<name>emitted beforeupdate:<name>. It is the only mechanic that is correct in uncontrolled,v-model,defineModel-parent and composable modes without a double emit (analysis in §3). The DOM ships this exact pair (beforetogglecancelable →toggle), and it matches the codebase's.preventidiom.update:<name>details keepreason/eventfor analytics; itscancel()is a dev-warn no-op.2. Types
Starter reason unions (additive; Drawer's at
DrawerRoot.vue:12-19becomesChangeEventDetails<DrawerOpenChangeReason>, no rename):trigger-press,close-press,escape-key,outside-press,focus-outside(AlertDialog never emitsoutside-press)trigger-press,trigger-hover,item-press,list-navigation,sibling-open,escape-key,outside-press,focus-outsideopentrigger-press,input-change,list-navigation,item-press,escape-key,outside-press,focus-outsidemodelValueitem-press,list-navigation,clear-press,input-cleartrigger-hover,trigger-focus,trigger-press,escape-key,outside-press,sibling-opentrigger-hover,trigger-focus,escape-key,outside-press,focus-outsidetimeout,swipe,close-press,escape-key'imperative-action'is appended everywhere: slot-propclose()(Dialog/DialogRoot.vue:104), contextonOpenChangecalled without a reason, anduseX().setOpen().'none'is never emitted; it is the initiallastChangeDetails.reason. Parent prop writes (:openchanging) emit nothing, as today.3. Ordering analysis and the chosen mechanic
<DialogRoot v-model:open="open" @update:open="(v, d) => cond && d.cancel()">compiles (compiler-corebuildProps→dedupeProperties, which merges duplicateon*keys into an array in source order) to:At runtime
emit()calls an array handler in order, synchronously;mergeProps(used byv-bind="forwarded"inAlertDialog/AlertDialogRoot.vue) also concatenates existing before incoming. So the writer runs first ifv-modelis written first, the listener first otherwise, but the writer is unconditional. Whichever order,_ctx.openis alreadyfalsewhenemit()returns. WithuseVModel({ passive: false })(Dialog/DialogRoot.vue:71-74) the emit is the computed setter, so this all happens inside the component's ownopen.value = false. A flag checked afteremit()cannot stop the parent write; the component seesprops.openflip on the next pre-flush regardless.Mechanics rejected: a revert re-emit works but fires every
update:openlistener twice, delivers a bogus(true, …)to analytics and composableonUpdate, and is visible toflush: 'sync'watchers. Documentingcancel()as uncontrolled-only makes it a silent no-op in the mode the docs recommend (guides/controlled-state.md).The pre-event mechanic, step by step, inside
setState(value, reason, event):value === state.value.detailsobject;emit('beforeUpdate:open', value, details), synchronous.details.isCanceled: record it inlastChangeDetails, returnfalse. Nothing else runs.props.open === undefined),emit('update:open', value, details), setlastChangeDetails, returntrue.v-modelparent: the writer lives onupdate:open, which is never emitted on cancel; parent ref untouched, no re-render.defineModelparent: the parent'sv-model:open="model"compiles to the identical writer; its ownupdate:opento its grandparent is never triggered. NotedefineModelcannot be used inside reka roots:useModel's setter emits with one argument, so details would be dropped. Reka is onuseVModel/own state, so this only constrains us from ever switching, and it argues for owning the composable (§5).useDialog({ open?: Ref, onBeforeUpdate?, onUpdate? }); with a caller-owned ref, a cancelled request simply never writes it.Fixed for free: today's uncontrolled emits are asynchronous (vueuse
passivepath emits from a watcher), while Drawer's manual path is sync (DrawerRoot.vue:117-122). The shared composable makes both sync.4. Granular events
Keep them, unchanged, as the low-level layer.
DismissableLayer.vuealready gatesdismissonevent.defaultPrevented, so.preventkeeps working. One additive change:dismiss: []becomesdismiss: [details: { reason: 'escape-key' | 'outside-press' | 'focus-outside', event }], and content parts forward it (Dialog, Popover, Menu, Select, Combobox ContentImpl). That deletes thependingDismissReasoncapture hack atDrawer/DrawerContentImpl.vue:219-225. No deprecation; documentbeforeUpdate:*as the recommended entry point and the granular events as the escape hatch.5. Where it lands once
New
packages/core/src/shared/useControllableState.ts, exported fromshared/index.ts:Roots swap
useVModel(props, 'open', emit, { passive })(Dialog, Popover, Menu, Tooltip, HoverCard, Select, Combobox, Toast roots) for one call;useSingleOrMultipleValue.ts:47-51wraps it so Accordion/ToggleGroup/Listbox inherit it;useEmitAsProps.ts:33already spreads all args, so AlertDialog forwarding needs no change. Contexts gain areasonparameter (onOpenChange(value, reason?, event?)), the patternDrawerRoot.vue:71already uses.The #2723 composables must change:
useSwitch.ts:45,52anduseTabs.ts:138,146-148write straight into the passed ref with no emit channel, and the recipe pinsuseVModelin the shell. Amend the recipe so the composable ownsuseControllableStateand takesonBeforeUpdate/onUpdateoptions;useMenuRoot'sonOpenChange(Menu/useMenu.ts:74-79) is the first to gain areason.6. Decision checklist
update:*(Drawer's shape), not a parallel@open-changebeforeUpdate:<name>pre-event;cancel()onupdate:*is a no-opdismisson DismissableLayer carries{ reason, event }escapeKeyDown/pointerDownOutside/interactOutside/focusOutsideshared/useControllableStateand migrate roots offuseVModel(sync emit in uncontrolled mode)allowPropagation()(Base UI nested-popup semantics) in this passUnverified
dedupeProperties; no Vue compiler available to run here.useModel(defineModel) emitting a single argument.@before-update:opencompiles toonBeforeUpdate:openand is not misclassified byisModelListener(prefix isonUpdate:, so it should not be).Generated by Claude Code
zernonia commentedon Sep 4, 2026
Decisions
The proposal above is accepted as written. For the record:
update:*, Drawer's existing shape; no parallel@open-changeevent: yes.beforeUpdate:<name>pre-event; on cancel,update:*never fires, so thev-modelwriter never runs.cancel()on theupdate:*details is a dev-warn no-op: yes.dismisson DismissableLayer carries{ reason, event }, forwarded by the content parts; Drawer'spendingDismissReasoncapture goes away: yes.escapeKeyDown/pointerDownOutside/interactOutside/focusOutsidestay, undeprecated, as the low-level layer: yes.shared/useControllableState; every root migrates off vueuseuseVModel. Accepted side effect: uncontrolledupdate:*emits become synchronous, matching Drawer today: yes.allowPropagation(): no, not in this pass; the layer stack already routes Escape to the top layer only.Sequencing:
useControllableStateplus theChangeEventDetailstype is the first PR. The #2723 recipe is amended in the same PR so composables takeonBeforeUpdate/onUpdateoptions and own the controllable state. Per-family reason unions and thedismissdetails follow family by family, Dialog and Popover first.Generated by Claude Code
feat(shared): add useControllableState, ChangeEventDetails, dataState…
feat(Menu): own open state with useControllableState, thread change r…
fix(Menu): report the real dismiss reason and expose cancellation
feat(Dialog)!: own open with useControllableState and emit change det…
feat(Popover)!: own open with useControllableState and emit change de…
feat(Tooltip)!: own open with useControllableState and emit change de…
feat(HoverCard)!: own open with useControllableState and emit change …
feat(Combobox): pass change details for the input text (#2828)
chore(shared): remove the unused `useSingleOrMultipleValue` (#2828)
docs: prefer a component's own emit descriptions in the API meta (#2828)
docs(v3): migration section 29 for input text details and `grouped` v…
fix(Combobox): leave the input alone when a clear is cancelled (#2828)
docs(v3): scope the change-details claim and separate `text-content` …
chore(size): raise the full library limit to 187 kB (#2828, #2824)
fix(v3): complete change-details and data-model coverage (#2828, #2824)…
zernonia commentedon Oct 28, 2026
Done on
v3in #2910 → #3086.