Transition
Preset transition wrapper for keyed content switches, drill-in page pushes, list motion, and smooth size changes.
Usage
Best Practices
- Use
mode="out-in"for keyed panel switches so leaving content finishes before the new panel enters. - Use
TxTransitionPushfor hierarchical navigation (drilling into a sub-page and back): passdirection="forward"going in and"back"coming out. Sibling tab switches are not a push; keep them on a fade. - Use
smooth-sizewhen content height changes; use normalfade/slide-fade/reboundfor lists and repeated rows. - Keep list keys stable business ids.
Date.now()is fine for docs demos, but production reorderable lists should use persisted ids. - Keep durations short for repeated UI motion; reserve rebound for small affordances where overshoot is intentional.
API Reference
TxTransition Props
| Prop | Type | Default | Description |
|---|---|---|---|
preset | 'fade' | 'slide-fade' | 'rebound' | 'smooth-size' | 'fade' | Selects the transition class name. smooth-size delegates to TxTransitionSmoothSize only when group=false. |
group | boolean | false | Uses Vue TransitionGroup for keyed lists. Prefer fade, slide-fade, or rebound in list mode. |
tag | string | 'div' | Root tag forwarded to TransitionGroup when group=true. |
appear | boolean | true | Enables enter motion on initial render. |
mode | 'in-out' | 'out-in' | 'out-in' | Vue Transition mode for single-child transitions; ignored by TransitionGroup. |
duration | number | 180 | Motion duration in milliseconds, written to --tx-transition-duration. |
easing | string | 'cubic-bezier(0.2, 0, 0, 1)' | CSS timing function written to --tx-transition-easing. |
TxTransitionSmoothSize Props
| Prop | Type | Default | Description |
|---|---|---|---|
appear | boolean | true | Enables enter motion on initial render. |
mode | 'in-out' | 'out-in' | 'out-in' | Vue Transition mode for the keyed child inside TxAutoSizer. |
duration | number | 220 | Shared duration for the size measurement transition and inner motion. |
easing | string | 'cubic-bezier(0.2, 0, 0, 1)' | Shared easing for size and content motion. |
width | boolean | false | Animates width changes through TxAutoSizer. |
height | boolean | true | Animates height changes through TxAutoSizer. |
motion | 'fade' | 'slide-fade' | 'rebound' | 'fade' | Inner content motion while the wrapper animates size. |
TxTransitionPush Props
| Prop | Type | Default | Description |
|---|---|---|---|
direction | 'forward' | 'back' | 'forward' | forward pushes the new page in from the inline end and the old one out towards the start; back reverses both. Mirrored automatically in a right-to-left container. |
duration | number | 220 | Duration of the push and the height tween, in milliseconds. 0 swaps the page at once with no animation. |
easing | string | 'cubic-bezier(0.23, 1, 0.32, 1)' | Easing shared by the push, the crossfade and the height tween. Web Animations reads it, so it cannot be a CSS variable. |
height | boolean | true | Tweens the container from the old page's height to the new one's, then returns it to auto. |
appear | boolean | false | Pushes the first page in on mount as well, along direction; with no old page there is no height tween. |
Semantic Components
| Component | Preset |
|---|---|
TxTransitionFade | fade |
TxTransitionSlideFade | slide-fade |
TxTransitionRebound | rebound |
TxTransitionSmoothSize | size-aware wrapper with configurable inner motion |
TxTransitionPush | drill-in paging: a horizontal push with a height tween; its own implementation, not a preset |
Events
| Event | Payload | Description |
|---|---|---|
| - | - | TxTransition and the preset components above have no component-specific emits. Non-smooth TxTransition forwards Vue transition listener attributes to the underlying Transition / TransitionGroup; smooth-size mode forwards attrs to TxAutoSizer. |
before-enter | (el: Element) | TxTransitionPush: fires before the new page is inserted. |
after-enter | (el: Element) | TxTransitionPush: fires once the new page has pushed in; an enter cut short by the next switch does not fire. |
after-leave | (el: Element) | TxTransitionPush: fires once the old page has left the DOM, including when a same-key page replaces it mid-push. |
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Single keyed child for Transition, or keyed children when group=true. TxTransitionPush takes exactly one keyed element; changing its key turns the page. |
Content Switch (X)
Transition Content
Loading demo...
List Add/Remove (Y)
Transition List
Loading demo...
Page Push (Z)
Transition Push
Loading demo...
Overview
classandstyleare merged onto the outer.tx-transitionwrapper; other attrs are forwarded toTransition/TransitionGroupin non-smooth mode.smooth-sizeis a single-child mode. It wraps the child withTxAutoSizer, defaults to height animation, and keeps overflow hidden during measurement.group=trueswitches toTransitionGroup;modeno longer applies and each rendered item must have a stable key.TxTransitionPushis single-child too, and moves both pages at once with nomode: the old page is pinned where it stands, at its own size, asposition: absoluteand madeinert(no pointer, Tab stop or assistive-technology access), while the new page stays in flow and sets the container's height. Focus inside the old page is lost with it; the host moves focus to the new page when it switches.- The container's height tweens from the old page to the new one only during the switch, then returns to
auto. While anything moves the container isoverflow: clip, nothidden, so focusing the new page right away never scrolls the container; at rest nothing is clipped, so a focus ring inside a page is never cut off. - An interrupted switch continues from where things are drawn: the container starts from its mid-tween height, and a page still entering leaves from where it is. Turning back to the same key mid-push brings that page back from where the old one stopped.
- Presets share the
--tx-transition-durationand--tx-transition-easingCSS variables, except rebound enter easing uses its spring curve intentionally. - Under
prefers-reduced-motion: reduce, every preset collapses to a near-instant duration and drops itstranslateY/scaleoffsets, so switches and list motion still complete without animation.TxTransitionPushcrossfades in place over 120ms instead and lands the height at once;durationof0swaps the page with no animation at all.
Technologies
- Attribute note:
classandstyleland on the.tx-transitionwrapper; non-style attrs are forwarded to VueTransition/TransitionGroup, so they are not visible on the wrapper in tests. - Smooth-size note:
preset="smooth-size"delegates toTxTransitionSmoothSizeonly whengroup=false. In grouped lists, it still renders a transition name and should be avoided because the size-aware wrapper is single-child oriented. - Push note:
TxTransitionPushdrives the Web Animations API from the JS hooks of<Transition :css="false">: pages animatetranslate, leaving their owntransformalone, and the container animatesheight. A leave keeps its last frame withfill: 'forwards'until Vue removes the node. A page cut short is resumed fromgetComputedTiming().progress.class,styleand other attrs land on the.tx-transition-pushroot. - Verified coverage:
transition.test.tschecks preset-to-name mapping, timing CSS variables, group tags, smooth-size delegation,TxAutoSizersizing prop forwarding, semantic wrapper presets, forwarded attrs, and slot rendering. ForTxTransitionPushit checks the push keyframes in both directions and mirrored for right-to-left, pinning andinerton the leaving page, the[old, new]height keyframes (also when nothing enters),height=false,duration=0, the reduced-motion crossfade, interrupted and same-key turnaround switches,appear, and cancelling motion on unmount. - Component sources:
packages/tuffex/packages/components/src/transition/src/TxTransition.vue,TxTransitionSmoothSize.vue,TxTransitionFade.vue,TxTransitionSlideFade.vue,TxTransitionRebound.vue, andTxTransitionPush.vue. - Types:
packages/tuffex/packages/components/src/transition/src/types.tsexportsTransitionPreset,TxTransitionProps,TxTransitionSmoothSizeProps,TransitionPushDirection, andTxTransitionPushProps. - Export alias:
packages/tuffex/packages/components/src/transition/index.tsexports installable transition aliases, rawTx*components, prop types, and instance types. - Coverage:
packages/tuffex/packages/components/src/transition/__tests__/transition.test.tsverifies preset mapping, smooth-size behavior, semantic components, attrs, styles, slots, and the push, height, interrupt and fallback paths ofTxTransitionPush.
查看源码
packages/tuffex/packages/components/src/transition/index.ts