| 318 |
318 |
|
// into a two-position control. That is the granularity the description
|
| 319 |
319 |
|
// means when it says nothing, so this is emitted only when an app has said
|
| 320 |
320 |
|
// otherwise rather than defaulted here.
|
| 321 |
|
- |
if let Some(step) = field.step {
|
|
321 |
+ |
//
|
|
322 |
+ |
// A range takes its granularity from its curve as of makeover-layout
|
|
323 |
+ |
// 0.32.0, and every other kind keeps `Field::step`. See the crate header on
|
|
324 |
+ |
// what this renderer can and cannot do with a curve.
|
|
325 |
+ |
let step = if field.kind == FieldKind::Range {
|
|
326 |
+ |
field.curve.step()
|
|
327 |
+ |
} else {
|
|
328 |
+ |
field.step
|
|
329 |
+ |
};
|
|
330 |
+ |
if let Some(step) = step {
|
| 322 |
331 |
|
out.push_str(" step=\"");
|
| 323 |
332 |
|
escape_into(step, out);
|
| 324 |
333 |
|
out.push('"');
|
| 953 |
962 |
|
#[cfg(test)]
|
| 954 |
963 |
|
mod tests {
|
| 955 |
964 |
|
use super::*;
|
| 956 |
|
- |
use makeover_layout::{Accepted, Family};
|
|
965 |
+ |
use makeover_layout::{Accepted, Curve, Family};
|
| 957 |
966 |
|
|
| 958 |
967 |
|
fn field(kind: FieldKind) -> Field<'static> {
|
| 959 |
968 |
|
Field::new(kind, "title", "Title")
|
| 1002 |
1011 |
|
let mut f = field(FieldKind::Radio);
|
| 1003 |
1012 |
|
let options = [Choice::new("a", "A")];
|
| 1004 |
1013 |
|
f.options = &options;
|
| 1005 |
|
- |
let mut filling = Filling::default();
|
| 1006 |
|
- |
filling.control_attrs = Some(Markup(r#"data-host="1""#));
|
|
1014 |
+ |
let filling = Filling {
|
|
1015 |
+ |
control_attrs: Some(Markup(r#"data-host="1""#)),
|
|
1016 |
+ |
..Filling::default()
|
|
1017 |
+ |
};
|
| 1007 |
1018 |
|
let html = field_html(&f, &filling, &Emit::default());
|
| 1008 |
1019 |
|
assert!(!html.contains("data-host"), "{html}");
|
| 1009 |
1020 |
|
}
|
| 1258 |
1269 |
|
#[test]
|
| 1259 |
1270 |
|
fn a_range_is_a_range_input_and_carries_its_extent() {
|
| 1260 |
1271 |
|
let f = Field {
|
| 1261 |
|
- |
step: Some("0.01"),
|
|
1272 |
+ |
curve: Curve::Linear { step: Some("0.01") },
|
| 1262 |
1273 |
|
..Field::range("review", "Review above", "0", "1")
|
| 1263 |
1274 |
|
};
|
| 1264 |
1275 |
|
let html = field_html(&f, &Filling::of(Value::Text("0.72")), &Emit::default());
|
| 1270 |
1281 |
|
assert!(html.contains("step=\"0.01\""), "{html}");
|
| 1271 |
1282 |
|
}
|
| 1272 |
1283 |
|
|
|
1284 |
+ |
#[test]
|
|
1285 |
+ |
fn a_range_reads_its_granularity_off_the_curve_and_not_off_field_step() {
|
|
1286 |
+ |
// The 0.32.0 narrowing, at the renderer. `Field::step` on a range is a
|
|
1287 |
+ |
// site that has not been moved over, and emitting it would make the
|
|
1288 |
+ |
// control step by a number the curve never agreed to.
|
|
1289 |
+ |
let f = Field {
|
|
1290 |
+ |
step: Some("99"),
|
|
1291 |
+ |
..Field::range("review", "Review above", "0", "1")
|
|
1292 |
+ |
};
|
|
1293 |
+ |
let html = field_html(&f, &Filling::of(Value::Text("0.5")), &Emit::default());
|
|
1294 |
+ |
assert!(!html.contains("step="), "{html}");
|
|
1295 |
+ |
}
|
|
1296 |
+ |
|
|
1297 |
+ |
#[test]
|
|
1298 |
+ |
fn a_constant_ratio_curve_still_emits_a_linear_track() {
|
|
1299 |
+ |
// Honest shortfall rather than a silent one: HTML has no logarithmic
|
|
1300 |
+ |
// range input, so the browser draws the extent linearly. The value it
|
|
1301 |
+ |
// submits is still a value in the field's own units, which is what
|
|
1302 |
+ |
// every handler on this path reads. See the crate header.
|
|
1303 |
+ |
let f = Field {
|
|
1304 |
+ |
curve: Curve::Logarithmic {
|
|
1305 |
+ |
step: Some("0.001"),
|
|
1306 |
+ |
},
|
|
1307 |
+ |
..Field::range("attack", "Attack", "0.001", "5")
|
|
1308 |
+ |
};
|
|
1309 |
+ |
let html = field_html(&f, &Filling::of(Value::Text("0.005")), &Emit::default());
|
|
1310 |
+ |
assert!(html.contains("type=\"range\""), "{html}");
|
|
1311 |
+ |
assert!(html.contains("min=\"0.001\""), "{html}");
|
|
1312 |
+ |
assert!(html.contains("max=\"5\""), "{html}");
|
|
1313 |
+ |
assert!(html.contains("step=\"0.001\""), "{html}");
|
|
1314 |
+ |
}
|
|
1315 |
+ |
|
| 1273 |
1316 |
|
#[test]
|
| 1274 |
1317 |
|
fn a_number_with_bounds_is_still_typed_into() {
|
| 1275 |
1318 |
|
// The distinction the kind exists for, at the renderer where getting it
|