From a127f77602ae7a109121b776752e5edaf7d0d329 Mon Sep 17 00:00:00 2001 From: Glenn Skrzypczak Date: Sun, 10 Aug 2025 22:45:24 +0200 Subject: [PATCH] LibWeb/HTML: Implement default value of range inputs Range inputs now always uses the default value if the value attribute is not set and the input is not dirty. --- Libraries/LibWeb/HTML/HTMLInputElement.cpp | 2 ++ .../html/semantics/forms/the-input-element/range.txt | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index f510aec8fd8..c9a7b1c5040 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1728,6 +1728,8 @@ Utf16String HTMLInputElement::value_sanitization_algorithm(Utf16String const& va // as a floating-point number, of the default value. auto maybe_value = parse_floating_point_number(value); if (!is_valid_floating_point_number(value) || + // AD-HOC: Use the default value if the value has not been set. + (!m_dirty_value && !has_attribute(AttributeNames::value)) || // AD-HOC: The spec doesn't require these checks - but other engines do them. !maybe_value.has_value() || !isfinite(maybe_value.value())) { // The default value is the minimum plus half the difference between the minimum and the maximum, unless diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/range.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/range.txt index 5024a4f28ba..87dbadccbeb 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/range.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/range.txt @@ -2,8 +2,7 @@ Harness status: OK Found 25 tests -23 Pass -2 Fail +25 Pass Pass range type support on input element Pass range overflow styles Pass min attribute support on input element @@ -16,8 +15,8 @@ Pass the value is set to min when a smaller value than min attribute is given Pass the value is set to max when a larger value than max attribute is given Pass default value of min attribute in input type=range Pass default value of max attribute in input type=range -Fail default value when min and max attributes are given (= min plus half the difference between min and max) -Fail default value with step control when both min and max attributes are given +Pass default value when min and max attributes are given (= min plus half the difference between min and max) +Pass default value with step control when both min and max attributes are given Pass default value when both min and max attributes are given, while min > max Pass The default step scale factor is 1, unless min attribute has non-integer value Pass Step scale factor behavior when min attribute has integer value but max attribute is non-integer