sidebar: Fix collapsed to display icon only. (#743)

<img width="1056" alt="image"
src="https://github.com/user-attachments/assets/162f9e47-72ef-47c2-b3a4-9bc10682a624"
/>
This commit is contained in:
Jason Lee 2025-03-27 09:35:01 +08:00 committed by GitHub
parent a70a0f168d
commit e582d22f11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View file

@ -45,7 +45,11 @@ impl Collapsible for SidebarMenu {
}
impl RenderOnce for SidebarMenu {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
v_flex().gap_2().children(self.items)
v_flex().gap_2().children(
self.items
.into_iter()
.map(|item| item.collapsed(self.collapsed)),
)
}
}
@ -166,11 +170,12 @@ impl RenderOnce for SidebarMenuItem {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let is_submenu = self.is_submenu();
let is_open = self.is_open();
let is_collapsed = self.collapsed;
div()
.w_full()
.child(self.render_menu_item(window, cx))
.when(is_submenu && is_open, |this| {
.when(is_submenu && is_open && !is_collapsed, |this| {
this.child(
v_flex()
.border_l_1()

View file

@ -182,7 +182,6 @@ impl RenderOnce for SidebarToggleButton {
impl<E: Collapsible + IntoElement> RenderOnce for Sidebar<E> {
fn render(mut self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let is_collapsed = self.collapsed;
v_flex()
.id("sidebar")
.w(self.width)
@ -204,7 +203,11 @@ impl<E: Collapsible + IntoElement> RenderOnce for Sidebar<E> {
.child(
v_flex().id("content").flex_1().min_h_0().child(
div()
.children(self.content.into_iter().map(|c| c.collapsed(is_collapsed)))
.children(
self.content
.into_iter()
.map(|c| c.collapsed(self.collapsed)),
)
.gap_2()
.scrollable(self.view_id, ScrollbarAxis::Vertical),
),