diff --git a/thaw/src/nav/docs/mod.md b/thaw/src/nav/docs/mod.md index cf219b5..ad42652 100644 --- a/thaw/src/nav/docs/mod.md +++ b/thaw/src/nav/docs/mod.md @@ -53,7 +53,7 @@ view! { | --- | --- | --- | --- | | class | `MaybeProp,` | `Default::default()` | | | selected_value | `OptionModel` | `Default::default()` | The value of the currently selected navItem. | -| selected_category_value | `VecModel` | `vec![]` | Indicates a category that has a selected child Will show the category as selected if it is closed. | +| selected_category_value | `OptionModel` | `None` | Indicates a category that has a selected child Will show the category as selected if it is closed. | | nav_drawer_header | slot `Option` | `None` | | | nav_drawer_footer | slot `Option` | `None` | | | children | `Children` | | | diff --git a/thaw/src/nav/nav-drawer.css b/thaw/src/nav/nav-drawer.css index fe5be9f..c7a2a95 100644 --- a/thaw/src/nav/nav-drawer.css +++ b/thaw/src/nav/nav-drawer.css @@ -69,7 +69,8 @@ background-color: var(--colorNeutralBackground4Pressed); } -.thaw-nav-item--selected::after { +.thaw-nav-item--selected::after, +.thaw-nav-category-item--selected[aria-expanded="false"]::after { content: ""; position: absolute; width: 4px; diff --git a/thaw/src/nav/nav_category.rs b/thaw/src/nav/nav_category.rs index 7b50751..bd708c7 100644 --- a/thaw/src/nav/nav_category.rs +++ b/thaw/src/nav/nav_category.rs @@ -1,8 +1,8 @@ use super::NavDrawerInjection; use crate::Icon; -use leptos::{either::Either, html, prelude::*}; +use leptos::{context::Provider, either::Either, html, prelude::*}; use thaw_components::CSSTransition; -use thaw_utils::{class_list, StoredMaybeSignal, VecModelWithValue}; +use thaw_utils::{class_list, StoredMaybeSignal}; #[component] pub fn NavCategory( @@ -13,56 +13,9 @@ pub fn NavCategory( let nav_drawer = NavDrawerInjection::expect_context(); let value: StoredMaybeSignal<_> = value.into(); let group_ref = NodeRef::::new(); - let is_show_group = Memo::new(move |_| { - nav_drawer - .selected_category_value - .with(|selected_category_value| { - value.with(|value| match selected_category_value { - VecModelWithValue::T(v) => v == value, - VecModelWithValue::Option(v) => v.as_ref() == Some(value), - VecModelWithValue::Vec(v) => v.contains(value), - }) - }) - }); - - let on_click = move |_| { - let value = value.get_untracked(); - let is_show_group = is_show_group.get_untracked(); - nav_drawer - .selected_category_value - .update(|selected_category_value| { - match selected_category_value { - (None, None, Some(v)) => { - if is_show_group { - if let Some(index) = v.iter().position(|item| item == &value) { - v.remove(index); - } - } else { - v.push(value); - } - } - (None, Some(v), None) => { - if is_show_group { - *v = None; - } else { - *v = Some(value); - } - } - (Some(v), None, None) => { - if is_show_group { - v.clear(); - } else { - *v = value; - } - } - _ => unreachable!(), - } - - if is_show_group { - } else { - } - }); - }; + let is_show_group = RwSignal::new(false); + let is_selected_category = + Memo::new(move |_| value.with(|value| nav_drawer.is_selected_category(value))); let NavCategoryItem { class: item_class, @@ -72,9 +25,13 @@ pub fn NavCategory( view! {