vaadin / flow-components

Java counterpart of Vaadin Web Components
82 stars 63 forks source link

DatePicker with initialValue considered empty #6325

Open bananer opened 1 month ago

bananer commented 1 month ago

Description

Passing an initial value to the DatePicker constructur sets that initial value also as the "empty value". Consequently, when the value is unchanged (or changed back to the initial value) the DatePicker returns true from isEmpty()

Expected outcome

DatePicker with initialValue returns fals from isEmpty()

Minimal reproducible example

DatePicker(LocalDate.now()).isEmpty // returns true
DatePicker(LocalDate.now()).optionalValue // returns empty Optional

Workaround:

DatePicker().apply { value = LocalDate.now() }.isEmpty // returns false

Steps to reproduce

see above

Environment

Vaadin version(s): 24.3.12 OS: Debian 12

Browsers

Issue is not browser related

yuriy-fix commented 1 month ago

I would agree that it could be confusing, but unfortunately at the moment it's a documented behaviour and some users could rely on it. We would be able to change it with the upcoming major release. As a workaround you can set an initial value after initialisation of the field:

DatePicker datePicker = new DatePicker();
datePicker.setValue(LocalDate.now());