diff --git a/crates/ui-widgets/src/text/number.rs b/crates/ui-widgets/src/text/number.rs index b7a0d27f7..06fba69e7 100644 --- a/crates/ui-widgets/src/text/number.rs +++ b/crates/ui-widgets/src/text/number.rs @@ -603,7 +603,8 @@ impl Component for NumberField<'_, V> { /// text value, the selection and the text actions to the same node. fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) { let rule = self.rule(); - let numeric = match self.shown_number(cx.value()) { + // A value that is not finite shows the dash, as a mixed one does, and has no number to read. + let numeric = match self.shown_number(cx.value()).filter(|value| value.is_finite()) { Some(value) => Numeric::new(value, rule.bounds()), None => Numeric::empty(rule.bounds()), }; diff --git a/crates/ui-widgets/tests/it/text/access.rs b/crates/ui-widgets/tests/it/text/access.rs index 0bb7683f3..9c532abc7 100644 --- a/crates/ui-widgets/tests/it/text/access.rs +++ b/crates/ui-widgets/tests/it/text/access.rs @@ -51,3 +51,22 @@ fn a_number_field_that_keeps_its_name_is_described_by_its_caption() { } } } + +/// A number field whose value is not a number shows the dash and its node carries no numeric value, only the range; +/// with a number it carries that number. +#[trial] +fn a_number_field_with_no_number_has_no_numeric_value() { + use craft_ui::text::NumberField; + + for (value, read) in [(f64::NAN, None), (12.0, Some(12.0))] { + let field = Rc::new(Cell::new(egui::Id::NULL)); + let seen = field.clone(); + let mut fixture = Fixture::new(move |ui| { + let mut shown = Some(value); + seen.set(NumberField::new("Offset", Bind::bound(&mut shown)).id_salt("offset").show(ui).response.id); + }); + fixture.settle(); + let numeric = fixture.tree().numeric(field.get()).expect("the field's node is numeric"); + assert_eq!(numeric.value, read, "the numeric value of a field holding {value}"); + } +}