fix: tab component remove

This commit is contained in:
luoxiao 2024-01-21 15:03:38 +08:00 committed by luoxiaozero
parent 1e30144292
commit 8c4c5027ee
2 changed files with 16 additions and 0 deletions

View file

@ -146,6 +146,14 @@ impl TabsInjection {
v.push(options);
});
}
pub(crate) fn remove_tab_options(&self, key: &String) {
self.tab_options_vec.update(|v| {
if let Some(index) = v.iter().position(|tab| &tab.key == key) {
v.remove(index);
}
});
}
}
pub(crate) fn use_tabs() -> TabsInjection {

View file

@ -22,6 +22,14 @@ pub fn Tab(
label,
});
on_cleanup({
let key = key.clone();
let tabs = tabs.clone();
move || {
tabs.remove_tab_options(&key);
}
});
view! {
<div class=class_list![
"thaw-tab", ("thaw-tab--hidden", move || key != tabs.get_key()), move || class.get()