Skip to content

Commit dd076df

Browse files
feat: add dialogAccessibleName to DatePickerI18n (#9804)
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
1 parent cf45872 commit dd076df

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎vaadin-date-picker-flow-parent/vaadin-date-picker-flow-integration-tests/src/main/java/com/vaadin/flow/component/datepicker/DatePickerI18nPage.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public DatePickerI18nPage() {
3535
DatePickerI18n i18n = new DatePickerI18n();
3636
i18n.setToday("Custom today");
3737
i18n.setCancel("Custom cancel");
38+
i18n.setDialogAccessibleName("Custom calendar");
3839
i18n.setMonthNames(List.of("Custom January", "Custom February",
3940
"Custom March", "Custom April", "Custom May", "Custom June",
4041
"Custom July", "Custom August", "Custom September",

‎vaadin-date-picker-flow-parent/vaadin-date-picker-flow-integration-tests/src/test/java/com/vaadin/flow/component/datepicker/DatePickerI18nIT.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public void setI18n_i18nIsApplied() {
5151
overlayContent.getTodayButton().getText());
5252
Assert.assertEquals("Custom cancel",
5353
overlayContent.getCancelButton().getText());
54+
Assert.assertEquals("Custom calendar",
55+
overlayContent.getDomAttribute("aria-label"));
5456
Assert.assertTrue(overlayContent.getVisibleMonthCalendars().stream()
5557
.anyMatch(month -> month.getHeaderText()
5658
.contains("Custom January")));
@@ -68,6 +70,8 @@ public void setI18n_setEmptyI18n_defaultI18nIsRestored() {
6870
Assert.assertEquals("Today", overlayContent.getTodayButton().getText());
6971
Assert.assertEquals("Cancel",
7072
overlayContent.getCancelButton().getText());
73+
Assert.assertEquals("Calendar",
74+
overlayContent.getDomAttribute("aria-label"));
7175
Assert.assertTrue(overlayContent.getVisibleMonthCalendars().stream()
7276
.anyMatch(month -> month.getHeaderText().contains("January")));
7377
}

‎vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/main/java/com/vaadin/flow/component/datepicker/DatePicker.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,7 @@ public static class DatePickerI18n implements Serializable {
15911591
private int firstDayOfWeek;
15921592
private String today;
15931593
private String cancel;
1594+
private String dialogAccessibleName;
15941595
private LocalDate referenceDate;
15951596
private String badInputErrorMessage;
15961597
private String requiredErrorMessage;
@@ -1846,6 +1847,34 @@ public DatePickerI18n setCancel(String cancel) {
18461847
return this;
18471848
}
18481849

1850+
/**
1851+
* Gets the accessible name of the overlay content.
1852+
*
1853+
* @return the accessible name of the overlay content
1854+
* @since 25.3
1855+
*/
1856+
public String getDialogAccessibleName() {
1857+
return dialogAccessibleName;
1858+
}
1859+
1860+
/**
1861+
* Sets the accessible name of the overlay content, announced by screen
1862+
* readers when the overlay opens. Defaults to {@code Calendar}.
1863+
* <p>
1864+
* Unlike {@link DatePicker#setAriaLabel(String)}, which names the
1865+
* input, this only names the overlay content.
1866+
*
1867+
* @param dialogAccessibleName
1868+
* the accessible name of the overlay content
1869+
* @return this instance for method chaining
1870+
* @since 25.3
1871+
*/
1872+
public DatePickerI18n setDialogAccessibleName(
1873+
String dialogAccessibleName) {
1874+
this.dialogAccessibleName = dialogAccessibleName;
1875+
return this;
1876+
}
1877+
18491878
/**
18501879
* Gets the {@code referenceDate}.
18511880
*

‎vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/test/java/com/vaadin/flow/component/datepicker/DatePickerTest.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ void setDateFormats_throwsExceptionWhenSecondArgIsNull() {
256256
() -> i18n.setDateFormats("MM-yyyy-dd", null));
257257
}
258258

259+
@Test
260+
void dialogAccessibleName_defaultIsNull_setAndGet() {
261+
DatePickerI18n i18n = new DatePickerI18n();
262+
263+
Assertions.assertNull(i18n.getDialogAccessibleName());
264+
265+
Assertions.assertSame(i18n, i18n.setDialogAccessibleName("Kalenteri"));
266+
Assertions.assertEquals("Kalenteri", i18n.getDialogAccessibleName());
267+
}
268+
259269
@Test
260270
void datePickerFirstDayOfTheWeek() {
261271
DatePicker germanDatePicker = new DatePicker();

0 commit comments

Comments
 (0)