@@ -192,6 +192,105 @@ describe("MonthDropdown", () => {
192192 dropdownDateFormat = getMonthDropdown ( { locale : "ru" } ) ;
193193 expect ( dropdownDateFormat . textContent ) . toContain ( "декабрь" ) ;
194194 } ) ;
195+
196+ it ( "calls the supplied onChange function when a month is selected using arrows and enter key" , ( ) => {
197+ const monthReadView = safeQuerySelector (
198+ monthDropdown ,
199+ ".react-datepicker__month-read-view" ,
200+ ) ;
201+ fireEvent . click ( monthReadView ) ;
202+
203+ const monthOptions = safeQuerySelectorAll (
204+ monthDropdown ,
205+ ".react-datepicker__month-option" ,
206+ ) ;
207+
208+ const monthOption = monthOptions [ 3 ] ! ;
209+ fireEvent . keyDown ( monthOption , { key : "ArrowDown" } ) ;
210+
211+ const nextMonthOption = monthOptions [ 4 ] ;
212+ expect ( document . activeElement ) . toEqual ( nextMonthOption ) ;
213+
214+ fireEvent . keyDown ( document . activeElement ! , { key : "Enter" } ) ;
215+ expect ( handleChangeResult ) . toEqual ( 4 ) ;
216+ } ) ;
217+
218+ it ( "handles ArrowUp key navigation correctly" , ( ) => {
219+ const monthReadView = safeQuerySelector (
220+ monthDropdown ,
221+ ".react-datepicker__month-read-view" ,
222+ ) ;
223+ fireEvent . click ( monthReadView ) ;
224+
225+ const monthOptions = safeQuerySelectorAll (
226+ monthDropdown ,
227+ ".react-datepicker__month-option" ,
228+ ) ;
229+
230+ const monthOption = monthOptions [ 5 ] ! ;
231+ fireEvent . keyDown ( monthOption , { key : "ArrowUp" } ) ;
232+
233+ const prevMonthOption = monthOptions [ 4 ] ;
234+ expect ( document . activeElement ) . toEqual ( prevMonthOption ) ;
235+ } ) ;
236+
237+ it ( "handles Escape key to cancel dropdown" , ( ) => {
238+ const monthReadView = safeQuerySelector (
239+ monthDropdown ,
240+ ".react-datepicker__month-read-view" ,
241+ ) ;
242+ fireEvent . click ( monthReadView ) ;
243+
244+ const monthOptions = safeQuerySelectorAll (
245+ monthDropdown ,
246+ ".react-datepicker__month-option" ,
247+ ) ;
248+
249+ const monthOption = monthOptions [ 5 ] ! ;
250+ fireEvent . keyDown ( monthOption , { key : "Escape" } ) ;
251+
252+ expect (
253+ monthDropdown ?. querySelectorAll ( ".react-datepicker__month-dropdown" ) ,
254+ ) . toHaveLength ( 0 ) ;
255+ } ) ;
256+
257+ it ( "wraps around when using ArrowUp on first month" , ( ) => {
258+ const monthReadView = safeQuerySelector (
259+ monthDropdown ,
260+ ".react-datepicker__month-read-view" ,
261+ ) ;
262+ fireEvent . click ( monthReadView ) ;
263+
264+ const monthOptions = safeQuerySelectorAll (
265+ monthDropdown ,
266+ ".react-datepicker__month-option" ,
267+ ) ;
268+
269+ const firstMonthOption = monthOptions [ 0 ] ! ;
270+ fireEvent . keyDown ( firstMonthOption , { key : "ArrowUp" } ) ;
271+
272+ const lastMonthOption = monthOptions [ 11 ] ;
273+ expect ( document . activeElement ) . toEqual ( lastMonthOption ) ;
274+ } ) ;
275+
276+ it ( "wraps around when using ArrowDown on last month" , ( ) => {
277+ const monthReadView = safeQuerySelector (
278+ monthDropdown ,
279+ ".react-datepicker__month-read-view" ,
280+ ) ;
281+ fireEvent . click ( monthReadView ) ;
282+
283+ const monthOptions = safeQuerySelectorAll (
284+ monthDropdown ,
285+ ".react-datepicker__month-option" ,
286+ ) ;
287+
288+ const lastMonthOption = monthOptions [ 11 ] ! ;
289+ fireEvent . keyDown ( lastMonthOption , { key : "ArrowDown" } ) ;
290+
291+ const firstMonthOption = monthOptions [ 0 ] ;
292+ expect ( document . activeElement ) . toEqual ( firstMonthOption ) ;
293+ } ) ;
195294 } ) ;
196295
197296 describe ( "select mode" , ( ) => {
0 commit comments