Skip to content

Commit

Permalink
add autocomplete attributes
Browse files Browse the repository at this point in the history
fix #8
  • Loading branch information
jcornaz committed Dec 16, 2024
1 parent c7c4d8e commit 7c92a19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* implement `Default` for `Element` and `Attribute`
* `attr::disabled()` and `attr::autofocus()`
* `attr::charset_utf8()` and `elt::meta_charset_utf8()`
* `attr::autocomplete(type_: impl Into<Cow<'static, str>>)`, `attr::autocomplete_on()`, `attr::autocomplete_off()`


## [1.4.0] - 2024-12-13
Expand Down
15 changes: 15 additions & 0 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,21 @@ pub fn autofocus() -> Attribute {
Attribute::new_flag("autofocus")
}

/// `autocomplete` attribute
pub fn autocomplete(type_: impl Into<Cow<'static, str>>) -> Attribute {
Attribute::new("autocomplete", type_)
}

/// `autocomplete="on"` attribute
pub fn autocomplete_on() -> Attribute {
Attribute::new("autocomplete", "on")
}

/// `autocomplete="on"` attribute
pub fn autocomplete_off() -> Attribute {
Attribute::new("autocomplete", "off")
}

/// `disabled` attribute
pub fn disabled() -> Attribute {
Attribute::new_flag("disabled")
Expand Down
3 changes: 3 additions & 0 deletions tests/render_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ fn should_render_html_document() {
#[case(attr::required(), "required")]
#[case(attr::disabled(), "disabled")]
#[case(attr::autofocus(), "autofocus")]
#[case(attr::autocomplete("email"), "autocomplete=\"email\"")]
#[case(attr::autocomplete_on(), "autocomplete=\"on\"")]
#[case(attr::autocomplete_off(), "autocomplete=\"off\"")]
#[case(attr::pattern("foobar"), "pattern=\"foobar\"")]
#[case(attr::min("value"), "min=\"value\"")]
#[case(attr::max("value"), "max=\"value\"")]
Expand Down

0 comments on commit 7c92a19

Please sign in to comment.