@@ -44,6 +44,40 @@ describe("MonthDropdown", () => {
4444 monthDropdown = getMonthDropdown ( ) ;
4545 } ) ;
4646
47+ it ( "sets proper ARIA on read view button and toggles aria-expanded" , ( ) => {
48+ const monthReadView = safeQuerySelector (
49+ monthDropdown ,
50+ ".react-datepicker__month-read-view" ,
51+ ) ;
52+ expect ( monthReadView . getAttribute ( "aria-label" ) ) . toBe ( "Select Month" ) ;
53+ expect ( monthReadView . getAttribute ( "aria-haspopup" ) ) . toBe ( "listbox" ) ;
54+ expect ( monthReadView . getAttribute ( "aria-expanded" ) ) . toBe ( "false" ) ;
55+
56+ fireEvent . click ( monthReadView ) ;
57+
58+ const monthReadViewAfterOpen = safeQuerySelector (
59+ monthDropdown ,
60+ ".react-datepicker__month-read-view" ,
61+ ) ;
62+ expect ( monthReadViewAfterOpen . getAttribute ( "aria-expanded" ) ) . toBe ( "true" ) ;
63+ } ) ;
64+
65+ it ( "applies aria-label to each month option in scroll dropdown" , ( ) => {
66+ const monthReadView = safeQuerySelector (
67+ monthDropdown ,
68+ ".react-datepicker__month-read-view" ,
69+ ) ;
70+ fireEvent . click ( monthReadView ) ;
71+
72+ const firstOption = safeQuerySelector (
73+ monthDropdown ,
74+ ".react-datepicker__month-option" ,
75+ ) ;
76+ expect ( firstOption . getAttribute ( "aria-label" ) ) . toBe (
77+ "Select Month January" ,
78+ ) ;
79+ } ) ;
80+
4781 it ( "shows the selected month in the initial view" , ( ) => {
4882 expect ( monthDropdown ?. textContent ) . toContain ( "December" ) ;
4983 } ) ;
@@ -307,6 +341,14 @@ describe("MonthDropdown", () => {
307341 ) ;
308342 } ) ;
309343
344+ it ( "adds aria-label to select element" , ( ) => {
345+ monthDropdown = getMonthDropdown ( { dropdownMode : "select" } ) ;
346+ const select = monthDropdown . querySelector < HTMLSelectElement > (
347+ ".react-datepicker__month-select" ,
348+ ) ;
349+ expect ( select ?. getAttribute ( "aria-label" ) ) . toBe ( "Select Month" ) ;
350+ } ) ;
351+
310352 it ( "renders month options with default locale" , ( ) => {
311353 monthDropdown = getMonthDropdown ( { dropdownMode : "select" } ) ;
312354 const options = monthDropdown . querySelectorAll ( "option" ) ;
@@ -325,6 +367,24 @@ describe("MonthDropdown", () => {
325367 "December" ,
326368 ] ) ;
327369 } ) ;
370+ // Accessibility of options
371+ it ( "adds aria-label and aria-selected to options in select mode" , ( ) => {
372+ monthDropdown = getMonthDropdown ( { dropdownMode : "select" , month : 11 } ) ;
373+ const select = monthDropdown . querySelector < HTMLSelectElement > (
374+ ".react-datepicker__month-select" ,
375+ ) ;
376+ const options = Array . from (
377+ select ?. querySelectorAll ( "option" ) ?? [ ] ,
378+ ) as HTMLOptionElement [ ] ;
379+ expect ( options [ 0 ] ?. getAttribute ( "aria-label" ) ) . toBe (
380+ "Select Month January" ,
381+ ) ;
382+ expect ( options [ 11 ] ?. getAttribute ( "aria-label" ) ) . toBe (
383+ "Select Month December" ,
384+ ) ;
385+ expect ( options [ 11 ] ?. getAttribute ( "aria-selected" ) ) . toBe ( "true" ) ;
386+ expect ( options [ 0 ] ?. getAttribute ( "aria-selected" ) ) . toBe ( "false" ) ;
387+ } ) ;
328388 // Short Month Names
329389 it ( "renders month options with short name and default locale" , ( ) => {
330390 monthDropdown = getMonthDropdown ( {
0 commit comments