diff options
| author | 2020-01-03 16:41:16 +0100 | |
|---|---|---|
| committer | 2020-01-03 16:41:16 +0100 | |
| commit | 0b663ca82aa4fccb95ada3dd01d82cbaec6acc24 (patch) | |
| tree | af6f1203c58dd6ea1a371947b8a8431c9d6c0c6e /web | |
| parent | 986f01237f227ad2eaabda982324fc26840cb12b (diff) | |
| download | iced-0b663ca82aa4fccb95ada3dd01d82cbaec6acc24.tar.gz iced-0b663ca82aa4fccb95ada3dd01d82cbaec6acc24.tar.bz2 iced-0b663ca82aa4fccb95ada3dd01d82cbaec6acc24.zip | |
add(web): support password field
Diffstat (limited to '')
| -rw-r--r-- | web/src/widget/text_input.rs | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 99792c84..eedc25bc 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -32,6 +32,7 @@ pub struct TextInput<'a, Message> {      _state: &'a mut State,      placeholder: String,      value: String, +    is_secure: bool,      width: Length,      max_width: Length,      padding: u16, @@ -64,6 +65,7 @@ impl<'a, Message> TextInput<'a, Message> {              _state: state,              placeholder: String::from(placeholder),              value: String::from(value), +            is_secure: false,              width: Length::Fill,              max_width: Length::Shrink,              padding: 0, @@ -73,6 +75,14 @@ impl<'a, Message> TextInput<'a, Message> {          }      } +    /// Converts the [`TextInput`] into a secure password input. +    /// +    /// [`TextInput`]: struct.TextInput.html +    pub fn password(mut self) -> Self { +        self.is_secure = true; +        self +    } +          /// Sets the width of the [`TextInput`].      ///      /// [`TextInput`]: struct.TextInput.html @@ -161,6 +171,10 @@ where                  "value",                  bumpalo::format!(in bump, "{}", self.value).into_bump_str(),              ) +            .attr( +                "type", +                bumpalo::format!(in bump, "{}", if self.is_secure { "password" } else { "text" }).into_bump_str(), +            )              .on("input", move |root, vdom, event| {                  let text_input = match event.target().and_then(|t| {                      t.dyn_into::<web_sys::HtmlInputElement>().ok() | 
