AutoSizer
Automatically follows content width and height changes with resize and FLIP transitions.
AutoSizer
Automatically follows content width and height changes with resize and FLIP transitions.
Typical scenarios:
- Smooth outer height transitions when switching Tabs content
- Smooth width transitions when a Button toggles
loading
Built on
ResizeObserver. When images/async rendering change size, it re-measures automatically.
Basic Usage
Height Only (Recommended for Tabs/Accordion)
AutoSizer height
Demo will load when visible.
Width Follow (Inside Flex Containers)
When AutoSizer is a flex item and the parent stretches it with
flex: 1orwidth: 100%, it may look like it is not following content.
AutoSizer width in flex
Demo will load when visible.
Pull-down Content Height Follow (Filters/Search)
AutoSizer height for dropdown
Demo will load when visible.
Dialog Content Height Follow (Simulated)
AutoSizer height for dialog
Demo will load when visible.
Width Only (Recommended for Button Content Changes)
AutoSizer width
Demo will load when visible.
Number Transition + Width Follow (NumberFlow)
AutoSizer + NumberFlow
Demo will load when visible.
Smooth Text Transform + Width Follow (TextTransformer)
This example enables
width + heightfollow and sets outeroverflow-hiddento clip blur overflow.
AutoSizer + TextTransformer
Demo will load when visible.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | div | Root element tag used for the measured outer wrapper. |
innerAs | string | div | Inner element tag that wraps slot content. |
width | boolean | true | Enables width measurement and style application. |
height | boolean | true | Enables height measurement and style application. |
inline | boolean | - | Forces inline sizing; when omitted, width-only mode uses inline layout automatically. |
durationMs | number | 200 | Resize / FLIP transition duration in milliseconds. |
easing | string | ease | CSS timing function used for resize / FLIP transitions. |
outerClass | string | overflow-hidden | Class applied to the outer wrapper before forwarded attrs classes. |
innerClass | string | - | Class applied to the inner content wrapper. |
rounding | 'none' | 'round' | 'floor' | 'ceil' | ceil | Rounding strategy for measured width and height values. |
immediate | boolean | true | Measures immediately after mount when enabled. |
rafBatch | boolean | true | Batches resize measurement through requestAnimationFrame when available. |
Expose
| Name | Type | Description |
|---|---|---|
refresh() | () => Promise<void> | Manually remeasures the configured target. |
flip(action) | (action: () => void | Promise<void>) => Promise<void> | Runs an action while auto-resize is paused, then performs a size FLIP transition and remeasures. |
action(fn, options?) | (fn: (el: HTMLElement) => void | Promise<void>, options?: AutoSizerActionOptions | detect) => Promise<any> | Runs a mutation against the inner or outer element and returns before / after snapshots with changed keys. |
size | Ref<{ width: number; height: number } | null> | Latest measured size from the auto-resize utility. |
Interaction Contract
- The outer wrapper receives forwarded attrs, merged class/style, and auto-resize styles; the inner wrapper owns the measured content with
display: flow-root. - Width-only mode uses inline layout automatically unless
inline=falseis set explicitly. flip(action)pauses auto-resize while the action runs, performs a size FLIP transition, then re-enables measurement.action(fn, options?)snapshots the selected target before and after mutation and returns detected change keys.observeTarget,rounding,immediate,rafBatch,durationMs, andeasingare forwarded to the underlying resize/FLIP utilities.