Accordion
Stacked sections that open and close. Single mode keeps one open; multiple mode opens each on its own.
Every answer lists the files it read, with the page for each figure.
Files stay in the project they were added to. Deleting the project deletes them.
Not available on this plan.
Summaries export as Markdown or PDF, sources included.
Open: sources
interviews-q3.pdf, tickets-sept.csv
22 of 24 passed. Two need your judgement.
Usage
use hydroxy_leptos::accordion::*;
use leptos::prelude::*;
#[component]
pub fn Demo() -> impl IntoView {
let (open, set_open) = signal(vec!["sources".to_string()]);
view! {
// Uncontrolled, single: opening one item closes the other.
<Accordion
items=vec![
AccordionEntry::new("citing"),
AccordionEntry::new("files"),
AccordionEntry::new("sharing").disabled(),
AccordionEntry::new("export"),
]
default_value=vec!["citing".to_string()]
>
<AccordionItem value="citing">
<AccordionTrigger>"How sources are cited"</AccordionTrigger>
<AccordionContent>"Every answer lists the files it read, with the page for each figure."</AccordionContent>
</AccordionItem>
<AccordionItem value="files">
<AccordionTrigger>"What happens to uploaded files"</AccordionTrigger>
<AccordionContent>"Files stay in the project they were added to. Deleting the project deletes them."</AccordionContent>
</AccordionItem>
<AccordionItem value="sharing">
<AccordionTrigger>"Team sharing"</AccordionTrigger>
<AccordionContent>"Not available on this plan."</AccordionContent>
</AccordionItem>
<AccordionItem value="export">
<AccordionTrigger>"Exporting a summary"</AccordionTrigger>
<AccordionContent>"Summaries export as Markdown or PDF, sources included."</AccordionContent>
</AccordionItem>
</Accordion>
// Controlled, multiple: several items open at once.
<div>
<p>"Open: " {move || open.get().join(", ")}</p>
<Accordion
items=vec![AccordionEntry::new("sources"), AccordionEntry::new("checks")]
value=open
on_value_change=move |v| set_open.set(v)
multiple=true
>
<AccordionItem value="sources">
<AccordionTrigger>"Sources"</AccordionTrigger>
<AccordionContent>"interviews-q3.pdf, tickets-sept.csv"</AccordionContent>
</AccordionItem>
<AccordionItem value="checks">
<AccordionTrigger>"Checks"</AccordionTrigger>
<AccordionContent>"22 of 24 passed. Two need your judgement."</AccordionContent>
</AccordionItem>
</Accordion>
</div>
}
}use dioxus::prelude::*;
use hydroxy_dioxus::accordion::{Accordion, AccordionContent, AccordionEntry, AccordionItem, AccordionTrigger};
#[component]
pub fn AccordionDemo() -> Element {
let mut open = use_signal(|| vec!["sources".to_string()]);
rsx! {
// Uncontrolled, single: opening one item closes the other.
Accordion {
items: vec![
AccordionEntry::new("citing"),
AccordionEntry::new("files"),
AccordionEntry::new("sharing").disabled(),
AccordionEntry::new("export"),
],
default_value: vec!["citing".to_string()],
AccordionItem { value: "citing",
AccordionTrigger { "How sources are cited" }
AccordionContent { "Every answer lists the files it read, with the page for each figure." }
}
AccordionItem { value: "files",
AccordionTrigger { "What happens to uploaded files" }
AccordionContent { "Files stay in the project they were added to. Deleting the project deletes them." }
}
AccordionItem { value: "sharing",
AccordionTrigger { "Team sharing" }
AccordionContent { "Not available on this plan." }
}
AccordionItem { value: "export",
AccordionTrigger { "Exporting a summary" }
AccordionContent { "Summaries export as Markdown or PDF, sources included." }
}
}
// Controlled, multiple: several items open at once.
div {
p { "Open: {open().join(\", \")}" }
Accordion {
items: vec![AccordionEntry::new("sources"), AccordionEntry::new("checks")],
value: Some(open()),
on_value_change: move |v| open.set(v),
multiple: true,
AccordionItem { value: "sources",
AccordionTrigger { "Sources" }
AccordionContent { "interviews-q3.pdf, tickets-sept.csv" }
}
AccordionItem { value: "checks",
AccordionTrigger { "Checks" }
AccordionContent { "22 of 24 passed. Two need your judgement." }
}
}
}
}
}
Anatomy
| Component | data-part | Renders |
|---|---|---|
Accordion | root | Provides the machine. data-orientation=vertical |
AccordionItem | item | Wraps one section. data-state=open|closed, data-disabled |
AccordionTrigger | heading, trigger | h3 around a button: aria-expanded, aria-controls, data-state |
AccordionContent | content | role=region, aria-labelledby, hidden when closed |
Keyboard
| Key | Does |
|---|---|
Enter / Space | Opens or closes the focused item |
ArrowDown / ArrowUp | Next / previous enabled trigger. Wraps at the ends |
Home / End | First / last enabled trigger |
Tab | Moves through triggers and open content in page order |
Props
| Prop | Type | Notes |
|---|---|---|
items | Vec<AccordionEntry> | Required. Order and disabled state |
value | Option<Vec<String>> | Controlled open items. Pair with on_value_change |
default_value | Vec<String> | Initially open items when uncontrolled |
multiple | bool | Allow several items open at once. Default false |
collapsible | bool | Single mode: the open item can close. Default true |
on_value_change | Callback<Vec<String>> | Called when the user opens or closes an item |