Skip to content

Min constraint silently ignored in YearMonthField #112

@javier-godoy

Description

@javier-godoy

Describe the bug

When a min is set on YearMonthField and the current value is below that minimum, the component does not clamp to the minimum. A missing else if in __normalizeValue() causes the else branch to run after the min-clamping block, overwriting the clamped value with the original out-of-range value.

if (this.min && intValue < this._minAsNumber){
    this.value = ...;  // clamp to min
    this.date  = ...;
} if (this.max && intValue > this._maxAsNumber){  // <-- missing `else`
    this.value = ...;
    this.date  = ...;
} else {
    this.value = value;  // overwrites the clamped value when min is violated
}

Expected behavior

Setting a min later than the current value should clamp the displayed value to min.

Minimal reproducible example

YearMonthField field = new YearMonthField();
field.setValue(YearMonth.of(2024, 1));
field.setMin(YearMonth.of(2024, 6));
// field displays 2024-01 instead of 2024-06

Add-on Version

4.6.1-SNAPSHOT

Vaadin Version

N/A

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions