Skip to content

Commit

Permalink
docs(island): provide correct Tab fn (leptos-rs#131)
Browse files Browse the repository at this point in the history
Co-authored-by: Arthur Vinchon <arthur.vinchon@allegrodvt.com>
  • Loading branch information
vinchona and allegrodvt-arvinchon authored Nov 5, 2024
1 parent 04199a8 commit 52cb91e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/islands.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,22 @@ And let’s modify the `Tab` island to use that context to show or hide itself:

```rust
#[island]
fn Tab(children: Children) -> impl IntoView {
fn Tab(index: usize, children: Children) -> impl IntoView {
let selected = expect_context::<ReadSignal<usize>>();
view! {
<div style:display=move || if selected() == index {
"block"
} else {
"none"
}>
// ...
<div
style:background-color="lightgreen"
style:padding="10px"
style:display=move || if selected() == index {
"block"
} else {
"none"
}
>
{children()}
</div>
}
}
```

Now the tabs behave exactly as I’d expect. `Tabs` passes the signal via context to each `Tab`, which uses it to determine whether it should be open or not.
Expand Down

0 comments on commit 52cb91e

Please sign in to comment.