) -> Self {
+ Self {
+ props,
+ link,
+ left_element_ref: Default::default(),
+ left_element_width: Default::default(),
+ right_element_ref: Default::default(),
+ right_element_width: Default::default(),
+ }
}
fn update(&mut self, _: Self::Message) -> ShouldRender {
@@ -102,6 +116,17 @@ impl Component for InputGroup {
}
fn view(&self) -> Html {
+ let input_style = match (self.left_element_width, self.right_element_width) {
+ (Some(left), None) => format!("padding-left:{}px", left.max(MIN_HORIZONTAL_PADDING)),
+ (None, Some(right)) => format!("padding-right:{}px", right.max(MIN_HORIZONTAL_PADDING)),
+ (Some(left), Some(right)) => format!(
+ "padding-left:{}px;padding-right:{}px",
+ left.max(MIN_HORIZONTAL_PADDING),
+ right.max(MIN_HORIZONTAL_PADDING)
+ ),
+ _ => Default::default(),
+ };
+
html! {
+
{left_element}
}
- } else {
- html!()
- }
- }
- {
- if let Some(icon) = self.props.left_icon {
+ } else if let Some(icon) = self.props.left_icon {
html! {
}
@@ -145,11 +168,15 @@ impl Component for InputGroup {
onkeyup={self.props.onkeyup.clone()}
onkeydown={self.props.onkeydown.clone()}
value=self.props.value.clone()
+ style=input_style
/>
{
if let Some(right_element) = self.props.right_element.clone() {
html! {
-
+
{right_element}
}
@@ -160,4 +187,23 @@ impl Component for InputGroup {
}
}
+
+ fn rendered(&mut self, _first_render: bool) {
+ let left_old_value = self.left_element_width.take();
+ self.left_element_width = self
+ .left_element_ref
+ .cast::()
+ .map(|x| x.client_width());
+
+ let right_old_value = self.right_element_width.take();
+ self.right_element_width = self
+ .right_element_ref
+ .cast::()
+ .map(|x| x.client_width());
+
+ if left_old_value != self.left_element_width || right_old_value != self.right_element_width
+ {
+ self.link.send_message(());
+ }
+ }
}