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.
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 opentoggles whether the box is visible, and the box animates as it appears and goes.animate: .expandmeasures the heightautowould give, animates to that number, then hands the height back, so the box keeps growing with its content..expandon the way in is.collapseon the way out, so the box needs noexit:.
A reader who asked for reduced motion sees the box open at once (Respect reduced motion).