ResizeBox
A container that animates between explicit width and height targets.
Usage
Explicit Size Targets
The parent supplies width / height targets; resize-start / resize-end mark where each transition begins and ends.
Loading demo...
Best Practices
- Use
TxResizeBoxwhen the parent already knows the compact and expanded targets; for content-driven changes such as images, async rendering, or wrapping, useTxAutoSizer. - Set only the axes you own; an unset axis keeps its intrinsic size.
- Give responsive targets as CSS lengths such as
min(420px, 100%)so narrow screens don't overflow. - Keep
clipon when content is larger than the compact target; turn it off only for intentional overflow. - Treat
resize-start/resize-endas lifecycle notifications; the props are the source of truth for size.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | div | Root element tag; forwarded attrs, class, and style land on the root. |
width | number | string | undefined | Width target: finite numbers become px, non-empty strings pass through as CSS lengths; unset keeps the intrinsic width. |
height | number | string | undefined | Height target, with the same rules as width. |
duration | number | 300 | Width and height transition duration in ms. |
easing | string | cubic-bezier(0.22, 1, 0.36, 1) | Timing function shared by both size transitions. |
disabled | boolean | false | Removes the transition so new targets apply at once; disabling mid-resize ends the lifecycle. |
clip | boolean | true | Applies overflow: hidden to the root. |
Events
| Event | Payload | Description |
|---|---|---|
resize-start | () | Fires when a size target changes with animation on; changes during a resize stay in the same lifecycle. |
resize-end | () | Fires when the last width/height transition ends, the safety timer fires, or a resize is disabled. |
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Content rendered directly in the root, without extra wrapping or measurement. |
Exposed Methods
| Name | Type | Description |
|---|---|---|
rootEl | HTMLElement | null | The current root element. |
animating | boolean | Whether a size transition lifecycle is active. |
Overview
- Finite numbers become px; non-empty strings pass through, so
%,rem,calc(), andmin()work directly.undefined,null, non-finite numbers, and blank strings leave the axis unset. - CSS lengths are not validated: negative and invalid values go to the browser as-is, and if no transition runs, the safety timer still ends the lifecycle.
- Only the root's own
width/heighttransitions count; transition events from children or other properties are ignored. - With
disabled, target changes snap without events; under reduced motion the transition shortens to0.01msand the lifecycle still ends. - Changing only the slot content never starts a resize; there is no content measurement,
ResizeObserver, orv-model.
Technologies
- Size changes ride a CSS
transitionon the root; the lifecycle ends ontransitionendor a duration-based safety timer. - Source:
packages/tuffex/packages/components/src/resize-box/.
查看源码
packages/tuffex/packages/components/src/resize-box/index.ts