How-to

Website

Web app

Open a box to the height of its content

CSS cannot animate to height: auto, so a box of details that should slide open to whatever height its text needs takes .expand. Press Details and the box opens; press it again and it closes:

Needs: nothing besides the page. It claims /: paste it into a new project, or replace the starter's src/pages/Home.wf with it.

wf

page Details(path: "/", title: "Details", description: "A box that opens smoothly.") { state open = false Heading("Details").h1 Button("Details") { on click { open = !open } } show open { Stack(animate: .expand) { Text("As much text as there is.") } } }

How it works

  • show open toggles whether the box is visible, and the box animates as it appears and goes.
  • animate: .expand measures the height auto would give, animates to that number, then hands the height back, so the box keeps growing with its content.
  • .expand on the way in is .collapse on the way out, so the box needs no exit:.

A reader who asked for reduced motion sees the box open at once (Respect reduced motion).