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.
This commit is contained in:
Glenn Skrzypczak 2025-08-10 22:45:24 +02:00 committed by Tim Flynn
commit a127f77602
Notes: github-actions[bot] 2025-08-14 15:06:56 +00:00
2 changed files with 5 additions and 4 deletions

View file

@ -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

View file

@ -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