[yew-devel] [PATCH yew-widget-toolkit] TabPanel/SelectionView: add an option to force rendering all tabs/views
Shannon Sterz
s.sterz at proxmox.com
Thu Jun 26 14:48:05 CEST 2025
this is useful when these components contain fields that should be
registered in a `FormContext` via a `Form`. as all fields need to be
properly rendered for registration.
Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
src/widget/selection_view.rs | 18 +++++++++++++++++-
src/widget/tab/tab_panel.rs | 18 +++++++++++++++++-
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/src/widget/selection_view.rs b/src/widget/selection_view.rs
index 8ba17706..5f3ba549 100644
--- a/src/widget/selection_view.rs
+++ b/src/widget/selection_view.rs
@@ -71,6 +71,16 @@ pub struct SelectionView {
#[prop_or_default]
#[builder]
pub page_cache: bool,
+
+ /// Whether the views should be rendered dynamically or should be rendered all at once.
+ /// All rendered views that are not currently selected will be hidden via the `display: none`
+ /// CSS property.
+ ///
+ /// This is useful when using a SelectionView in a [`crate::widget::form::Form`] as all fields
+ /// in all views need to be rendered for proper registration.
+ #[prop_or_default]
+ #[builder]
+ pub force_render_all: bool,
}
impl Default for SelectionView {
@@ -136,9 +146,15 @@ impl Component for PwtSelectionView {
.context(ctx.link().callback(Msg::VisibilityChanged))
.unzip();
+ let mut render_set = IndexSet::new();
+
+ if props.force_render_all {
+ render_set.extend(props.builders.keys().cloned());
+ }
+
Self {
active: None,
- render_set: IndexSet::new(),
+ render_set,
_selection_observer,
visibility: visibility.unwrap_or_default(),
_visibility_handle,
diff --git a/src/widget/tab/tab_panel.rs b/src/widget/tab/tab_panel.rs
index aa06d585..6b72c70d 100644
--- a/src/widget/tab/tab_panel.rs
+++ b/src/widget/tab/tab_panel.rs
@@ -84,6 +84,16 @@ pub struct TabPanel {
#[prop_or_default]
#[builder]
pub tab_bar_style: TabBarStyle,
+
+ /// Whether the tabs should be rendered dynamically or should be rendered all at once.
+ /// All rendered tabs that are not currently selected will be hidden via the `display: none`
+ /// CSS property.
+ ///
+ /// This is useful when using a TabPanel in a [`crate::widget::form::Form`] as all fields
+ /// in all tabs need to be rendered for proper registration.
+ #[prop_or_default]
+ #[builder]
+ pub force_render_all: bool,
}
impl Default for TabPanel {
@@ -240,11 +250,17 @@ impl Component for PwtTabPanel {
(None, tools)
};
+ let view = props
+ .view
+ .clone()
+ .force_render_all(props.force_render_all)
+ .selection(self.selection.clone());
+
Column::new()
.with_std_props(props.as_std_props())
.class("pwt-panel")
.with_child(html! {<div {class}>{title}{bar}{tools}</div>})
- .with_child(props.view.clone().selection(self.selection.clone()))
+ .with_child(view)
.into()
}
}
--
2.39.5
More information about the yew-devel
mailing list