]> git.proxmox.com Git - ui/proxmox-yew-widget-toolkit.git/commitdiff
list: set yew keys on all list items to keep item state
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 30 Nov 2024 08:41:10 +0000 (09:41 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 3 Dec 2024 09:27:51 +0000 (10:27 +0100)
And remove unused code.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
src/widget/list.rs

index af266d0d9ed368a995b9d9d6909bac0431196ca7..814ebeca1cbe2730508412d0d57e1feab5aeecf7 100644 (file)
@@ -100,7 +100,6 @@ pub struct PwtList {
     viewport_size_observer: Option<SizeObserver>,
     viewport_scrollbar_size: Option<f64>,
     viewport_scroll_top: usize,
-    set_viewport_scroll_top: Option<usize>,
 
     table_ref: NodeRef,
     table_size_observer: Option<SizeObserver>,
@@ -175,12 +174,14 @@ impl PwtList {
                     let separator = separator.emit(pos);
                     content.add_child(
                         Container::new()
+                            .key(format!("sep-{pos}"))
                             .class("pwt-list-separator")
                             .with_child(separator),
                     );
                 }
             }
-            let row = props.renderer.emit(pos);
+            let mut row = props.renderer.emit(pos);
+            row.set_key(format!("row-{pos}"));
             content.add_child(row);
         }
 
@@ -205,7 +206,6 @@ impl Component for PwtList {
             viewport_scrollbar_size: None,
             viewport_ref: NodeRef::default(),
             viewport_scroll_top: 0,
-            set_viewport_scroll_top: None,
 
             table_ref: NodeRef::default(),
             table_size_observer: None,
@@ -292,13 +292,5 @@ impl Component for PwtList {
                 self.table_size_observer = Some(size_observer);
             }
         }
-        if let Some(top) = self.set_viewport_scroll_top.take() {
-            // Note: we delay setting ScrollTop until we rendered the
-            // viewport with correct height. Else, set_viewport_scroll_top can
-            // fail because the viewport is smaller.
-            if let Some(el) = self.viewport_ref.cast::<web_sys::Element>() {
-                el.set_scroll_top(top as i32);
-            }
-        }
     }
 }