vaadin / flow-components

Java counterpart of Vaadin Web Components
100 stars 66 forks source link

Weekdays in DatePicker with I18N are not aligned #6353

Closed javier-godoy closed 2 months ago

javier-godoy commented 3 months ago

Description

If I configure I18n in a DatePicker, the weekdays are not stretched. For instance, in the following image (left), "Sun" seems to be displayed above July 1. Compare to a DatePicker instance without further configuration (right) image

Expected outcome

I would expect both DatePickers to look similar.

Minimal reproducible example

    DatePicker field1 = new DatePicker();
    DatePicker field2 = new DatePicker();

    DatePickerI18n i18n = new DatePickerI18n();
    DateFormatSymbols dfs = DateFormatSymbols.getInstance(Locale.ENGLISH);
    i18n.setMonthNames(List.of(dfs.getMonths()));
    i18n.setWeekdays(List.of(dfs.getWeekdays()));
    i18n.setWeekdaysShort(List.of(dfs.getShortWeekdays()));
    add(field1, field2);
    field1.setI18n(i18n);

Steps to reproduce

  1. Add the snippet above to a view.
  2. Open each DatePicker popup.
  3. Notice how "Sun" seems to be displayed above July 1.

Environment

Vaadin version(s): 24.3.13 Browser: Chrome 125

Browsers

No response

sissbruecker commented 3 months ago

The problem is that converting the result of DateFormatSymbols.getWeekdays or DateFormatSymbols.getShortWeekdays into a List returns 8 items instead of 7.

For example:

System.out.println(String.join(",", dfs.getWeekdays()));
System.out.println(String.join(",", dfs.getShortWeekdays()));

Prints:

,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
,Sun,Mon,Tue,Wed,Thu,Fri,Sat

The JavaDoc mentions that you are supposed to access the results via an index specifically:

Gets weekday strings. For example: "Sunday", "Monday", etc. Returns: the weekday strings. Use Calendar. SUNDAY, Calendar. MONDAY, etc. to index the result array.

yuriy-fix commented 3 months ago

We could consider limiting the number of the weekdays rendered or/and warn user.