Skip to content

Commit e5725bf

Browse files
zernoniaclaude
andauthored
feat(v3): Tree, Toolbar, Pagination and Stepper composables (#2723) (#3074)
* feat(Pagination)!: usePagination composable with page change details (#2723) The page model goes through useControllableState: a cancellable beforeUpdate:page, update:page(value, details) with a PaginationChangeReason, and no emit when the page is unchanged. The parts are thin shells over shared surface builders; the root context's page is read-only and onPageChange takes a reason and event. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(Stepper)!: useStepper composable with step change details (#2723) The step model goes through useControllableState: a cancellable beforeUpdate:modelValue, update:modelValue(value, details) with a StepperChangeReason ('trigger-press', 'trigger-keydown', 'next-step', 'prev-step'), and no emit when the step is unchanged. Item, trigger, title and description render from shared surface builders; the root context's modelValue is read-only and changeModelValue takes a reason and event. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(Toolbar): useToolbar composable (#2723) Toolbar has no model: useToolbar returns the role="toolbar" surface, button and link surfaces and the context. ToolbarToggleGroup keeps forwarding ToggleGroupRoot's cancellable beforeUpdate:modelValue and update:modelValue details; tests cover both. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(Tree)!: useTree composable with selection and expanded change details (#2723) modelValue and expanded both go through useControllableState: a cancellable beforeUpdate:*, update:*(value, details) with TreeChangeReason ('item-press', 'item-keydown', 'range-select') or TreeExpandedChangeReason ('item-press', 'item-keydown'), and no emit when the value is unchanged (selections compare by getKey). propagateSelect and bubbleSelect are folded into one change, so a press emits once instead of up to three times. TreeItem renders from a shared surface builder; TreeVirtualizer stays a component and passes its keydown to range selection. The root context's modelValue and expanded are read-only; onSelect/onToggle take a reason and event. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(Pagination): regenerate API meta for the Tree, Pagination and Stepper emits Spell out PaginationList's slot union so the generated docs keep it instead of the PaginationItem alias. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(Tree): migration notes for the Tree, Pagination, Stepper and Toolbar composables Adds the roots to "Converted so far", the four reason unions, a "Tree, Pagination and Stepper" section to the migration guide and section 17 to the agent page. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Tree): no duplicate keys with propagate/bubble select; context setters bubbleSelect no longer appends a parent that is already selected, and propagateSelect no longer appends children that are already selected. v2 did both, so the next press removed only one copy and the item stayed selected. The root context gains setModelValue and setExpanded (single-emit writes for custom select-all / expand-all parts), and types items as T[] | undefined. The JSDoc no longer claims v2 emitted several times per press (its deep watcher batched the writes), and the range-select docs cover the TreeVirtualizer's Shift+Home/End/PageUp/PageDown/ ArrowLeft/ArrowRight. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Pagination): keep the value attribute on PaginationListItem v2 bound every prop onto the button, so it rendered value="N". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Stepper): block goToStep onto a disabled step; boolean slot types goToStep read the trigger at [step] instead of [step - 1] and tested the empty disabled attribute for truthiness, so it never blocked. It now returns false and emits nothing for a disabled step. The slot types goToStep/nextStep/prevStep as returning boolean, and useStepper().getItem derives the title and description ids from a reactive step. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(Tree): correct the emit-count claim; document the de-duplication, goToStep and context setters v2 emitted once per propagated or bubbled press (its deep watcher batched the writes), so the "up to three times" claim is dropped. What changed is that the emit is synchronous, carries details and has one cancellable beforeUpdate. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(Stepper): regenerate meta for the boolean slot navigation types Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Stepper): read the item's disabled state in goToStep, not the stale attribute The trigger's disabled attribute also encodes linear reachability and only updates on the next render, so two synchronous nextStep() calls stopped at step 2. Triggers now register a getter for their item's own disabled state. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 758d95a commit e5725bf

36 files changed

Lines changed: 2784 additions & 652 deletions

‎docs/content/docs/guides/migration-v3-agent.md‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ You are migrating a Vue project from Reka UI v2 to Reka UI v3. Work through the
8181

8282
**What changed.** `update:*` events on stateful roots now receive a second argument, a `ChangeEventDetails` object with `reason`, `event`, `isCanceled` and `cancel()`, and a cancellable `beforeUpdate:*` event fires before every change. `v-model` keeps working unchanged. Uncontrolled components emit synchronously from the interaction instead of from a watcher on the next tick, and a component that mounts uncontrolled and later receives a defined model value becomes controlled from then on, even if the model is later cleared to `undefined`.
8383

84-
Converted so far: `SwitchRoot`, `TabsRoot`, `Toggle`, `ToggleGroupRoot`, `CheckboxRoot`, `CheckboxGroupRoot`, `RadioGroupRoot`, `ListboxRoot`, `AccordionRoot` (`modelValue`), `DropdownMenuRoot`, `DropdownMenuSub`, `ContextMenuRoot`, `ContextMenuSub`, `MenubarRoot` (`modelValue`), `MenubarSub`, `DialogRoot`, `AlertDialogRoot`, `PopoverRoot`, `TooltipRoot`, `HoverCardRoot`, `CollapsibleRoot`, `DatePickerRoot` and `DateRangePickerRoot` (`open`, `view`), `CalendarRoot` and `RangeCalendarRoot` (`modelValue`, `placeholder`, `view`), `ColorAreaRoot`, `ColorFieldRoot`, `ColorSliderRoot` and `ColorSwatchPickerRoot` (`modelValue`), `ComboboxRoot` and `AutocompleteRoot` (`modelValue`, `open`; section 16), `NumberFieldRoot`, `PinInputRoot`, `RatingRoot`, `SliderRoot`, `TagsInputRoot`, `TagGroupRoot` and `EditableRoot` (`modelValue`; sections 17 and 18), and `SelectRoot` (`modelValue`, `open`; section 19). On the converted families an `update:*` event fires only when the value actually changes; re-selecting the current value emits nothing, and a multiple selection is compared entry by entry (a `ListboxRoot` with `multiple` and `selection-behavior="replace"` no longer emits a fresh `[value]` array for a re-pressed item). `ColorAreaRoot` also now emits `change` (declared but never fired in v2) on every pointer move and arrow-key step that changes the color, and `changeEnd` after each keyboard step as well as on pointer release; both carry a `Color` object (section 10). Treat every other family as still on the v2 single-argument shape; the [Migration to v3](./migration-v3) guide lists the families as they convert. `DrawerRoot` is not on this contract: its `update:open(value, details)` is unchanged from v2 (it fires before the change and `details.cancel()` inside it vetoes the change), it has no `beforeUpdate:open`, and `update:snapPoint` stays single-argument. Leave Drawer listeners unchanged.
84+
Converted so far: `SwitchRoot`, `TabsRoot`, `Toggle`, `ToggleGroupRoot`, `CheckboxRoot`, `CheckboxGroupRoot`, `RadioGroupRoot`, `ListboxRoot`, `AccordionRoot` (`modelValue`), `DropdownMenuRoot`, `DropdownMenuSub`, `ContextMenuRoot`, `ContextMenuSub`, `MenubarRoot` (`modelValue`), `MenubarSub`, `DialogRoot`, `AlertDialogRoot`, `PopoverRoot`, `TooltipRoot`, `HoverCardRoot`, `CollapsibleRoot`, `DatePickerRoot` and `DateRangePickerRoot` (`open`, `view`), `CalendarRoot` and `RangeCalendarRoot` (`modelValue`, `placeholder`, `view`), `ColorAreaRoot`, `ColorFieldRoot`, `ColorSliderRoot` and `ColorSwatchPickerRoot` (`modelValue`), `ComboboxRoot` and `AutocompleteRoot` (`modelValue`, `open`; section 16), `NumberFieldRoot`, `PinInputRoot`, `RatingRoot`, `SliderRoot`, `TagsInputRoot`, `TagGroupRoot` and `EditableRoot` (`modelValue`; sections 17 and 18), `SelectRoot` (`modelValue`, `open`; section 19), `TreeRoot` (`modelValue`, `expanded`; section 21), `PaginationRoot` (`page`), `StepperRoot` (`modelValue`), and `ToolbarToggleGroup` (through the `ToggleGroupRoot` it wraps). On the converted families an `update:*` event fires only when the value actually changes; re-selecting the current value emits nothing, and a multiple selection is compared entry by entry (a `ListboxRoot` with `multiple` and `selection-behavior="replace"` no longer emits a fresh `[value]` array for a re-pressed item). `ColorAreaRoot` also now emits `change` (declared but never fired in v2) on every pointer move and arrow-key step that changes the color, and `changeEnd` after each keyboard step as well as on pointer release; both carry a `Color` object (section 10). Treat every other family as still on the v2 single-argument shape; the [Migration to v3](./migration-v3) guide lists the families as they convert. `DrawerRoot` is not on this contract: its `update:open(value, details)` is unchanged from v2 (it fires before the change and `details.cancel()` inside it vetoes the change), it has no `beforeUpdate:open`, and `update:snapPoint` stays single-argument. Leave Drawer listeners unchanged.
8585

8686
**How to find it.** Search for listeners and emit declarations on those roots: `@update:open`, `@update:model-value`, `@update:modelValue`, `@update:placeholder`, `'update:open'`, `'update:modelValue'`, `'update:placeholder'`, `onUpdate:open`, `onUpdate:modelValue`, `onUpdate:placeholder`, `defineEmits` in components that wrap one of the roots, `useForwardPropsEmits`, `emitted('update:open')` and `toHaveBeenCalledWith` in tests, and `watch(` calls that react to these models.
8787

@@ -97,7 +97,7 @@ Converted so far: `SwitchRoot`, `TabsRoot`, `Toggle`, `ToggleGroupRoot`, `Checkb
9797
}
9898
```
9999
100-
The reason unions, all exported from `reka-ui`, are `DialogOpenChangeReason` (also exported as `AlertDialogOpenChangeReason`), `PopoverOpenChangeReason`, `TooltipOpenChangeReason`, `HoverCardOpenChangeReason`, `MenuOpenChangeReason` (shared by the DropdownMenu, ContextMenu and Menubar parts, and also exported as `DropdownMenuOpenChangeReason`, `ContextMenuOpenChangeReason` and `MenubarChangeReason`), `SwitchChangeReason`, `TabsChangeReason`, `ToggleChangeReason`, `ToggleGroupChangeReason`, `CheckboxChangeReason`, `CheckboxGroupChangeReason`, `RadioGroupChangeReason`, `ListboxChangeReason`, `AccordionChangeReason`, `CollapsibleChangeReason`, `DatePickerOpenChangeReason`, `DateRangePickerOpenChangeReason`, `CalendarChangeReason`, `RangeCalendarChangeReason`, `ColorAreaChangeReason`, `ColorFieldChangeReason`, `ColorSliderChangeReason`, `ColorSwatchPickerChangeReason`, `ComboboxChangeReason`, `ComboboxOpenChangeReason` (the `open` reasons of both `ComboboxRoot` and `AutocompleteRoot`), `AutocompleteChangeReason`, `NumberFieldChangeReason`, `PinInputChangeReason`, `RatingChangeReason`, `SliderChangeReason`, `TagsInputChangeReason`, `TagGroupChangeReason`, `EditableChangeReason`, `SelectChangeReason` and `SelectOpenChangeReason`. `details.reason` is the family union plus the shared `BaseChangeReason` (`'imperative-action'` for programmatic changes such as a slot's `close()`), so a `switch` over the family union alone is incomplete.
100+
The reason unions, all exported from `reka-ui`, are `DialogOpenChangeReason` (also exported as `AlertDialogOpenChangeReason`), `PopoverOpenChangeReason`, `TooltipOpenChangeReason`, `HoverCardOpenChangeReason`, `MenuOpenChangeReason` (shared by the DropdownMenu, ContextMenu and Menubar parts, and also exported as `DropdownMenuOpenChangeReason`, `ContextMenuOpenChangeReason` and `MenubarChangeReason`), `SwitchChangeReason`, `TabsChangeReason`, `ToggleChangeReason`, `ToggleGroupChangeReason`, `CheckboxChangeReason`, `CheckboxGroupChangeReason`, `RadioGroupChangeReason`, `ListboxChangeReason`, `AccordionChangeReason`, `CollapsibleChangeReason`, `DatePickerOpenChangeReason`, `DateRangePickerOpenChangeReason`, `CalendarChangeReason`, `RangeCalendarChangeReason`, `ColorAreaChangeReason`, `ColorFieldChangeReason`, `ColorSliderChangeReason`, `ColorSwatchPickerChangeReason`, `ComboboxChangeReason`, `ComboboxOpenChangeReason` (the `open` reasons of both `ComboboxRoot` and `AutocompleteRoot`), `AutocompleteChangeReason`, `NumberFieldChangeReason`, `PinInputChangeReason`, `RatingChangeReason`, `SliderChangeReason`, `TagsInputChangeReason`, `TagGroupChangeReason`, `EditableChangeReason`, `SelectChangeReason`, `SelectOpenChangeReason`, `TreeChangeReason`, `TreeExpandedChangeReason`, `PaginationChangeReason` and `StepperChangeReason`. `ToolbarToggleGroup` reports `ToggleGroupChangeReason`. `details.reason` is the family union plus the shared `BaseChangeReason` (`'imperative-action'` for programmatic changes such as a slot's `close()`), so a `switch` over the family union alone is incomplete.
101101
- Wrappers that forward with `useForwardPropsEmits` need no change.
102102
- Custom parts built on `injectAccordionRootContext()` or `injectCollapsibleRootContext()`: the Accordion root context's `modelValue` is now a readonly `ComputedRef`, so call `changeModelValue` instead of assigning it, and `changeModelValue(value, reason?, event?)` now takes an optional reason and native event and returns a boolean (`false` when the change was cancelled or did not change the value). On the Collapsible root context, `onOpenToggle(event?)` accepts the native event, `onContentFound(event)` is new, and `contentId` is backed by a ref, so assigning it also updates the trigger's `aria-controls`.
103103
- Tests: an assertion such as `expect(emit).toHaveBeenCalledWith(true)` or `expect(wrapper.emitted('update:open')[0]).toEqual([true])` now fails because of the extra argument. Assert on the first element (`[0][0]`) or use `expect.objectContaining({ reason: '…' })` for the details. Tests that awaited a tick for an uncontrolled emit may now see it synchronously; remove waits only if the test's intent is unchanged.
@@ -487,10 +487,41 @@ Converted so far: `SwitchRoot`, `TabsRoot`, `Toggle`, `ToggleGroupRoot`, `Checkb
487487

488488
**Verify.** Each select opens, selects and closes as before; forms submit the selected values; the type-check passes.
489489

490+
### 21. Tree, Pagination and Stepper
491+
492+
**What changed.**
493+
- `TreeRoot`, `PaginationRoot` and `StepperRoot` follow section 2: `beforeUpdate:modelValue` / `update:modelValue(value, details)` and `beforeUpdate:expanded` / `update:expanded(value, details)` on Tree, `beforeUpdate:page` / `update:page(value, details)` on Pagination, `beforeUpdate:modelValue` / `update:modelValue(value, details)` on Stepper. No emit when the value is unchanged; Tree selections compare by `getKey`.
494+
- With `propagateSelect` or `bubbleSelect`, a key that is already selected is no longer added a second time. v2 could list a parent (bubble) or a child (propagate) twice, and the next press removed only one copy. A press still emits once, as in v2, now synchronously with details and after one cancellable `beforeUpdate:modelValue`.
495+
- `TreeRoot` with `:model-value` and no `update:modelValue` listener no longer changes its selection on click (v2 kept a local copy). `expanded` already behaved this way. Mutating either array in place (`modelValue.push(…)` on the slot value) no longer emits.
496+
- Root contexts: Tree `modelValue` and `expanded` are read-only, `onSelect(value, reason?, event?)` / `onToggle(value, reason?, event?)` return a boolean, `handleMultipleReplace` takes the keyboard event as a fifth argument, `setModelValue(value, reason?, event?)` and `setExpanded(keys, reason?, event?)` are new and write in one change, and `items` is typed `T[] | undefined`; Pagination `page` is read-only and `onPageChange(value, reason?, event?)` returns a boolean; Stepper `modelValue` is read-only and `changeModelValue(value, reason?, event?)` returns a boolean, and the `StepperItem` context's refs are read-only.
497+
- `goToStep`, `nextStep` and `prevStep` (StepperRoot slot props and template ref) return `false` when blocked, unchanged or cancelled. v2 returned `undefined`.
498+
- `goToStep(step)` onto a disabled step (its `StepperItem` has `disabled`) is blocked: it returns `false` and emits nothing. v2's check never fired, so it moved there.
499+
- New and additive: `useTree()`, `usePagination()`, `useStepper()`, `useToolbar()`.
500+
501+
**How to find it.**
502+
- `TreeRoot` usages with `:model-value` / `:modelValue` and no `@update:model-value`, `@update:modelValue` or `v-model`.
503+
- `TreeRoot` with `propagate-select` or `bubble-select`, and code reading its selection that removes duplicates by hand or counts entries.
504+
- Calls to `goToStep(` with a step that can be disabled.
505+
- `injectTreeRootContext(`, `injectPaginationRootContext(`, `injectStepperRootContext(`, `injectStepperItemContext(` in custom parts; within them, assignments to `.modelValue.value`, `.expanded.value`, `.page.value`, `.step.value`, `.state.value`, `.disabled.value`, `.isFocusable.value`, and calls to `handleMultipleReplace`.
506+
- In-place mutation of a tree's selection or expanded array: `.push(`, `.splice(`, `.pop(` on the `TreeRoot` slot's `modelValue` / `expanded` or on the bound `v-model` array.
507+
- Uses of the return value of `goToStep(`, `nextStep(` or `prevStep(`.
508+
- Emit types in components that wrap these roots (`'update:modelValue'`, `'update:expanded'`, `'update:page'`).
509+
510+
**Rewrite rules.**
511+
- A `TreeRoot` bound with `:model-value` and no listener: if the developer meant it to be interactive, replace it with `v-model`; if only an initial selection was intended, replace it with `:default-value`. *Ask* when the intent is unclear.
512+
- Hand-written de-duplication of a propagated or bubbled selection: leave it (it is now a no-op). Code that counted duplicated entries: *ask*.
513+
- A `goToStep(` that relied on reaching a disabled step: *ask* whether the step should stay disabled.
514+
- Custom parts: `ctx.modelValue.value = v` on Tree → `ctx.onSelect(item)` for a toggle-style selection, or `ctx.setModelValue(v)` when the code writes a whole selection (select-all, clear). `ctx.expanded.value = keys` → `ctx.setExpanded(keys)` (expand-all, collapse-all), or `ctx.onToggle(item)` for a single item. `ctx.page.value = n` → `ctx.onPageChange(n)`. Stepper `ctx.modelValue.value = n` → `ctx.changeModelValue(n)`.
515+
- In-place mutation of a tree's selection or expanded array: replace it with an assignment of a new array (`model.value = [...model.value, item]`).
516+
- Code that tested the result of `goToStep`, `nextStep` or `prevStep` against `undefined`: compare against `false` instead. Leave calls whose result is ignored.
517+
- Wrapper emit types: add the `details` element, importing `ChangeEventDetails` and the reason union (`TreeChangeReason`, `TreeExpandedChangeReason`, `PaginationChangeReason`, `StepperChangeReason`) from `reka-ui`. Wrappers that use `useForwardPropsEmits` need no change.
518+
519+
**Verify.** The type-check passes; selecting, expanding and Shift-range-selecting in each tree, paging, and stepping behave as before; a propagated or bubbled selection lists each key once; a disabled step cannot be reached through `goToStep`.
520+
490521
### Report
491522

492523
When you are done, give the developer:
493524

494525
1. The list of files you changed, grouped by the section above that required the change.
495-
2. Every `active` / `inactive` selector, every `require()`, every hand-built month or year switcher, every color model kept as a hex string, every gradient helper call, every prop read off a part ref, every other `--scrollbar-width` use, every overlay-less modal dialog, every form-input context assignment from section 17 every TagsInput / Editable handler from section 18 and every app reliance on a re-press emit from section 19 that you left unchanged because the rule said to ask, with file and line.
526+
2. Every `active` / `inactive` selector, every `require()`, every hand-built month or year switcher, every color model kept as a hex string, every gradient helper call, every prop read off a part ref, every other `--scrollbar-width` use, every overlay-less modal dialog, every form-input context assignment from section 17, every TagsInput / Editable handler from section 18, every app reliance on a re-press emit from section 19, and every count of duplicated tree selection entries or `goToStep` onto a disabled step from section 21 that you left unchanged because the rule said to ask, with file and line.
496527
3. The result of the type-check, lint and test commands, compared with the baseline you recorded at the start.

0 commit comments

Comments
 (0)