[yew-devel] [PATCH yew-widget-toolkit 2/4] props: field builder/std props: add 'id' to the std field props
Dominik Csapak
d.csapak at proxmox.com
Thu May 22 13:31:08 CEST 2025
this is so we can add an id to a field where we only have a
`FieldBuilder`, for example in an `InpuPanel`
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/props/field_builder.rs | 11 +++++++++++
src/props/field_std_props.rs | 11 +++++++++++
2 files changed, 22 insertions(+)
diff --git a/src/props/field_builder.rs b/src/props/field_builder.rs
index 38cfb0c..9609596 100644
--- a/src/props/field_builder.rs
+++ b/src/props/field_builder.rs
@@ -100,6 +100,17 @@ pub trait FieldBuilder: Into<VNode> {
self.as_input_props_mut().label_id = id.into_prop_value();
}
+ /// Builder style method to set the id
+ fn id(mut self, id: impl IntoPropValue<Option<AttrValue>>) -> Self {
+ self.set_id(id);
+ self
+ }
+
+ /// Method to set the id
+ fn set_id(&mut self, id: impl IntoPropValue<Option<AttrValue>>) {
+ self.as_input_props_mut().id = id.into_prop_value();
+ }
+
/// Builder style method to set the submit flag
fn submit(mut self, submit: bool) -> Self {
self.set_submit(submit);
diff --git a/src/props/field_std_props.rs b/src/props/field_std_props.rs
index 38b1b5f..c33ba44 100644
--- a/src/props/field_std_props.rs
+++ b/src/props/field_std_props.rs
@@ -16,6 +16,10 @@ pub struct FieldStdProps {
#[prop_or_default]
pub label_id: Option<AttrValue>,
+ /// Html element Id for the field.
+ #[prop_or_default]
+ pub id: Option<AttrValue>,
+
/// Html tabindex attriute
#[prop_or_default]
pub tabindex: Option<i32>,
@@ -104,6 +108,13 @@ impl FieldStdProps {
);
}
+ if let Some(ref id) = self.id {
+ attr_map.insert(
+ AttrValue::Static("id"),
+ (id.clone(), ApplyAttributeAs::Attribute),
+ );
+ }
+
if let Some(ref tabindex) = self.tabindex {
attr_map.insert(
AttrValue::Static("tabindex"),
--
2.39.5
More information about the yew-devel
mailing list