Skip to content

Commit b864cd1

Browse files
MIKOLAJW197fnagel
authored andcommitted
Fix: Adapt datpicker.js for a11y
1 parent 7c6a9f0 commit b864cd1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ui/widgets/datepicker.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ function Datepicker() {
9999
firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
100100
isRTL: false, // True if right-to-left language, false if left-to-right
101101
showMonthAfterYear: false, // True if the year select precedes month, false for month then year
102-
yearSuffix: "" // Additional text to append to the year in the month headers
102+
yearSuffix: "", // Additional text to append to the year in the month headers,
103+
selectMonthLabel: "Select month", // Invisible label for month selector
104+
selectYearLabel: "Select year" // Invisible label for year selector
103105
};
104106
this._defaults = { // Global defaults for all the date picker instances
105107
showOn: "focus", // "focus" for popup on focus,
@@ -1910,7 +1912,8 @@ $.extend( Datepicker.prototype, {
19101912
( printDate.getTime() === today.getTime() ? " ui-state-highlight" : "" ) +
19111913
( printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "" ) + // highlight selected day
19121914
( otherMonth ? " ui-priority-secondary" : "" ) + // distinguish dates from other months
1913-
"' href='#'>" + printDate.getDate() + "</a>" ) ) + "</td>"; // display selectable date
1915+
"' href='#' aria-current='" + ( printDate.getTime() === currentDate.getTime() ? "true" : "false" ) + // mark date as selected for screen reader
1916+
"'>" + printDate.getDate() + "</a>" ) ) + "</td>"; // display selectable date
19141917
printDate.setDate( printDate.getDate() + 1 );
19151918
printDate = this._daylightSavingAdjust( printDate );
19161919
}
@@ -1940,6 +1943,8 @@ $.extend( Datepicker.prototype, {
19401943
changeMonth = this._get( inst, "changeMonth" ),
19411944
changeYear = this._get( inst, "changeYear" ),
19421945
showMonthAfterYear = this._get( inst, "showMonthAfterYear" ),
1946+
selectMonthLabel = this._get( inst, "selectMonthLabel" ),
1947+
selectYearLabel = this._get( inst, "selectYearLabel" ),
19431948
html = "<div class='ui-datepicker-title'>",
19441949
monthHtml = "";
19451950

@@ -1949,7 +1954,7 @@ $.extend( Datepicker.prototype, {
19491954
} else {
19501955
inMinYear = ( minDate && minDate.getFullYear() === drawYear );
19511956
inMaxYear = ( maxDate && maxDate.getFullYear() === drawYear );
1952-
monthHtml += "<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>";
1957+
monthHtml += "<select class='ui-datepicker-month' aria-label='" + selectMonthLabel + "' data-handler='selectMonth' data-event='change'>";
19531958
for ( month = 0; month < 12; month++ ) {
19541959
if ( ( !inMinYear || month >= minDate.getMonth() ) && ( !inMaxYear || month <= maxDate.getMonth() ) ) {
19551960
monthHtml += "<option value='" + month + "'" +
@@ -1984,7 +1989,7 @@ $.extend( Datepicker.prototype, {
19841989
endYear = Math.max( year, determineYear( years[ 1 ] || "" ) );
19851990
year = ( minDate ? Math.max( year, minDate.getFullYear() ) : year );
19861991
endYear = ( maxDate ? Math.min( endYear, maxDate.getFullYear() ) : endYear );
1987-
inst.yearshtml += "<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>";
1992+
inst.yearshtml += "<select class='ui-datepicker-year' aria-label='" + selectYearLabel + "' data-handler='selectYear' data-event='change'>";
19881993
for ( ; year <= endYear; year++ ) {
19891994
inst.yearshtml += "<option value='" + year + "'" +
19901995
( year === drawYear ? " selected='selected'" : "" ) +

0 commit comments

Comments
 (0)