Elastic#
Component <neo-elastic> is a block container that animates its height as the natural size of its content changes: toggled visibility, added items, swapped blocks, async-loaded payloads. A ResizeObserver pins the latest content height to the host; the transition rides --neo-easing / --neo-duration-scale so each theme paces it differently. Server-side morphs that swap content animate the height shift automatically.
A plain block container that smoothly animates its height when the natural size of the content changes.
Switch between states to watch the host animate from one content height to the next.
The selected state's markup and its scoped CSS. The CSS is wrapped in <style>@scope { ... }</style> and applies to the preview only. Edits change the preview above, applied live while Sync is on, or when you click Patch or Replace. Patch morphs the preview; Replace swaps it outright.
Signals
Datastar signals declared in the selected state's markup. Change a value to drive the preview, applied live while Sync is on, or when you click Patch.
Reference#
Attributes #
| Name | Type | Default | Description |
|---|---|---|---|
open | boolean | true | Open by default. Set open="false" to animate the host to 0px tall. |
reset-on-collapse | boolean | false | Swap content for [data-neo-async-placeholder] after the collapse transition. |
Slots #
| Name | Description |
|---|---|
[data-neo-async-placeholder] | Replacement content shown after collapse when reset-on-collapse is set. |
Events #
| Name | Detail | Bubbles | Description |
|---|---|---|---|
neo-elastic-start | { from: number, to: number } | yes | Fires at the start of a height transition. |
neo-elastic-end | { height: number } | yes | Fires once the height transition lands. |
Examples#
Toggle reveal#
The accordion case. While the inner is display: none the wrapper measures zero and the host collapses; on reveal it animates back to the natural content height. The button just flips the inner's hidden attribute; the host re-measures on its own.
The classic accordion case. While the inner is display:none the wrapper measures at zero height and the host shrinks all the way closed; on reveal it animates back to the natural content height.
Examples: Datastar#
Datastar morph patches that swap or re-render the inner content animate the height shift automatically; Elastic's ResizeObserver / MutationObserver re-pin on every reflow, so any server-driven content swap reads as a smooth transition without per-demo wiring.
Morphing during interaction#
A Datastar fat-morph can grow or shrink the content inside a <neo-elastic> mid-view. The host stays mounted across each morph and animates from the old height to the new one, no per-demo wiring. Autoplay cycles the states below to simulate the morphs.
Release notes
The server just morphed this card in place.
- Elastic re-measures on every morph.
- The host animates to the new height.
- The element stays mounted, so no reflow flash.
The selected state's markup and its scoped CSS. The CSS is wrapped in <style>@scope { ... }</style> and applies to the preview only. Edits change the preview above, applied live while Sync is on, or when you click Patch or Replace. Patch morphs the preview; Replace swaps it outright.
Signals
Datastar signals declared in the selected state's markup. Change a value to drive the preview, applied live while Sync is on, or when you click Patch.
Growing list#
A Datastar morph patch replaces the inner <ul> with a fresh count of items. The wrapper re-measures on every replacement and the host transitions between the old and new heights.
- First item
- Second item
Content swap#
Not just expand-from-zero: the host shrinks or grows between two differently sized blocks. Whatever the wrapper measures, the host transitions to. Re-toggling mid-flight retargets the latest height instead of finishing the old one.
Short summary: one sentence and out.
The same container animates between wildly different content sizes.
- Each toggle reads the new natural height.
- Mid-animation interrupts retarget the latest height.
- Resizing the viewport reflows; ResizeObserver re-pins.
Async placeholder#
Combine reset-on-collapse with a <template data-neo-async-placeholder> to reload content through the placeholder. Opening reveals the skeleton and posts to the server, which morphs the loaded panel into the slot; collapsing reinstates the skeleton after the transition, so the next open loads fresh. Closing aborts an in-flight request. Load details, collapse, then reopen.