-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tabs works weird #88
Comments
I'm not sure I know what you mean. Can you write a minimal demo? |
@luoxiaozero As initially I have one active tab, but there could be more. So if I increase the number of the tabs the tabs header renders properly but the content stacks over each other as you can see in the picture: Tab header like this: Tab Content: So for some reason, the tab contents are always visible despite which tab is active. |
Sorry, I can't match your description with the picture, can you provide a minimum demo code? I tried the following code with no problem. let value = create_rw_signal(String::from("apple"));
let active_tabs = create_rw_signal(2);
view! {
<Tabs value>
<For each=move || (0..active_tabs.get()) key=|index| index.to_string() let:index>
<Tab key=index.to_string() label=(index + 1).to_string()>
"index:" {index}
</Tab>
</For>
</Tabs>
<Button on_click=move |_| active_tabs.update(|p| *p += 1)>"+1"</Button>
} |
The problem seems to be related to the For component. You can modify it as follows. Tabs(TabsProps {
value: tabs.selected_tab,
class: MaybeSignal::Static(String::new()),
children: Children::to_children(move || {
Fragment::new(vec![
For(ForProps {
each: move || (0..tabs.active_tabs.get()),
key: |index| index.to_string(),
children: move |index| {
+ Fragment::new(vec![
Tab(TabProps {
class: MaybeSignal::Static(String::new()),
key: index.to_string(),
label: (index + 1).to_string(),
children: Children::to_children(move || {
Fragment::new(vec![
query_editor::component().into_view(),
query_table::component().into_view(),
])
}),
})
+ .into_view()])
},
})
.into_view(),
button()
.on(ev::click, move |_| {
editors.add_editor();
tabs.active_tabs.update(|prev| *prev += 1);
tabs
.selected_tab
.update(|prev| *prev = (tabs.active_tabs.get() - 1).to_string());
})
.child("+")
.into_view(),
])
}) |
@luoxiaozero Thanks a lot, this is working. Can you briefly explain why I have to use Fragment in this case? I have used multiple times the For components but it worked without fragment. |
I don't know. The reason for the problem is not easy to find. |
@luoxiaozero and one more question. Maybe possible to add support for custom nodes for tabs? |
@luoxiaozero yes, because I would add a close button to the tabs for example. |
If you just want to add a close button, I can implement it like this https://www.naiveui.com/en-US/light/components/tabs#addable.vue (Do you have any style requirements?) |
@luoxiaozero i think the most general case would be if the tabs header can accept a totally customized children, styled nodes with custom logic. |
Hi, I added this feature in #91 . |
Hi there. I tried to use the Tabs component that way, but it seems the Tab content is stacking over each other as you can see in the picture below.

The tabs header works properly, but when I try to add more tabs dynamically, this vertical stacking occurs. Im attaching the code below. Thanks for your help.
The text was updated successfully, but these errors were encountered: