Skip to content

Commit

Permalink
Add classes & children props to TextField to allow icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Follpvosten committed Apr 22, 2020
1 parent 09975dd commit b19132a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/text_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct Props {
#[prop_or_default]
pub id: String,
#[prop_or_default]
pub classes: String,
#[prop_or_default]
pub value: String,
#[prop_or_default]
pub hint: String,
Expand All @@ -30,6 +32,8 @@ pub struct Props {
pub nolabel: bool,
#[prop_or_else(Callback::noop)]
pub onchange: Callback<String>,
#[prop_or_default]
pub children: Children,
}

pub enum Msg {
Expand Down Expand Up @@ -91,7 +95,10 @@ impl Component for TextField {
} else {
""
};
let classes = format!("mdc-text-field{}{}{}", disabled, outlined, nolabel);
let classes = format!(
"mdc-text-field{}{}{} {}",
disabled, outlined, nolabel, self.props.classes
);
let label = if self.props.nolabel {
html! {}
} else {
Expand Down Expand Up @@ -134,6 +141,7 @@ impl Component for TextField {
.callback(|e: InputData| Msg::ValueChanged(e.value));
html! {
<div class=classes id=&self.props.id ref=self.node_ref.clone()>
{ self.props.children.render() }
<input type="text"
value=self.props.value
class="mdc-text-field__input"
Expand Down

0 comments on commit b19132a

Please sign in to comment.