Skip to content

Commit 2884727

Browse files
committed
min/max length attributes that take integer
fix #13
1 parent f1c8a53 commit 2884727

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99

1010
### Added
1111

12-
* `attr::style`
12+
* `attr::style` attribute
13+
* `attr::minlength_u16` and `attr::maxlength_u16` attributes
1314

1415

1516
## [1.5.0] - 2024-12-16

src/attr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,21 @@ pub fn minlength(value: impl Into<Cow<'static, str>>) -> Attribute {
366366
Attribute::new("minlength", value)
367367
}
368368

369+
/// `minlength` attribute using a `u16` value
370+
pub fn minlength_u16(value: u16) -> Attribute {
371+
Attribute::new_int("minlength", value.into())
372+
}
373+
369374
/// `maxlength` attribute
370375
pub fn maxlength(value: impl Into<Cow<'static, str>>) -> Attribute {
371376
Attribute::new("maxlength", value)
372377
}
373378

379+
/// `maxlength` attribute using a `u16` value
380+
pub fn maxlength_u16(value: u16) -> Attribute {
381+
Attribute::new_int("maxlength", value.into())
382+
}
383+
374384
/// `multiple` attribute
375385
pub fn multiple() -> Attribute {
376386
Attribute::new_flag("multiple")

tests/render_spec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ fn should_render_html_document() {
9595
#[case(attr::max("value"), "max=\"value\"")]
9696
#[case(attr::minlength("value"), "minlength=\"value\"")]
9797
#[case(attr::maxlength("value"), "maxlength=\"value\"")]
98+
#[case(attr::minlength_u16(42), "minlength=\"42\"")]
99+
#[case(attr::maxlength_u16(42), "maxlength=\"42\"")]
98100
#[case(attr::multiple(), "multiple")]
99101
#[case(attr::placeholder("hello"), "placeholder=\"hello\"")]
100102
#[case(attr::rows(10), "rows=\"10\"")]

0 commit comments

Comments
 (0)