Skip to content

Commit

Permalink
fix: ensure invalid state is correctly set on slotted pickers (#7074)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored and vaadin-bot committed Jan 30, 2025
1 parent 850f880 commit 90fe955
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ public void setReadOnly(boolean readOnly) {
timePicker.setReadOnly(readOnly);
}

@Override
public void setInvalid(boolean invalid) {
HasValidationProperties.super.setInvalid(invalid);
datePicker.setInvalid(invalid);
timePicker.setInvalid(invalid);
}

/**
* Sets the label for this field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
import com.vaadin.flow.component.shared.SlotUtils;
import com.vaadin.flow.component.timepicker.TimePicker;
import com.vaadin.flow.dom.DomEvent;
import com.vaadin.flow.internal.nodefeature.ElementListenerMap;
import com.vaadin.tests.validation.AbstractBasicValidationTest;
Expand Down Expand Up @@ -124,6 +125,13 @@ public void setI18nAndCustomErrorMessage_validate_removeCustomErrorMessage_valid
Assert.assertEquals("Field is required", testField.getErrorMessage());
}

@Test
public void setInvalid_nestedPickersAreInvalid() {
testField.setInvalid(true);
Assert.assertTrue(getDatePicker().isInvalid());
Assert.assertTrue(getTimePicker().isInvalid());
}

@Override
protected DateTimePicker createTestField() {
return new DateTimePicker();
Expand All @@ -133,6 +141,10 @@ private DatePicker getDatePicker() {
return (DatePicker) SlotUtils.getChildInSlot(testField, "date-picker");
}

private TimePicker getTimePicker() {
return (TimePicker) SlotUtils.getChildInSlot(testField, "time-picker");
}

private void fireValidatedDomEvent() {
DomEvent validatedDomEvent = new DomEvent(testField.getElement(),
"validated", Json.createObject());
Expand Down

0 comments on commit 90fe955

Please sign in to comment.