@@ -74,6 +74,7 @@ export default class Month extends React.Component {
7474 } ;
7575
7676 MONTH_REFS = [ ...Array ( 12 ) ] . map ( ( ) => React . createRef ( ) ) ;
77+ QUARTER_REFS = [ ...Array ( 4 ) ] . map ( ( ) => React . createRef ( ) ) ;
7778
7879 isDisabled = ( date ) => utils . isDayDisabled ( date , this . props ) ;
7980
@@ -141,6 +142,10 @@ export default class Month extends React.Component {
141142 utils . getYear ( day ) === utils . getYear ( utils . newDate ( ) ) &&
142143 m === utils . getMonth ( utils . newDate ( ) ) ;
143144
145+ isCurrentQuarter = ( day , q ) =>
146+ utils . getYear ( day ) === utils . getYear ( utils . newDate ( ) ) &&
147+ q === utils . getQuarter ( utils . newDate ( ) ) ;
148+
144149 isSelectedMonth = ( day , m , selected ) =>
145150 utils . getMonth ( day ) === m && utils . getYear ( day ) === utils . getYear ( selected ) ;
146151
@@ -290,6 +295,37 @@ export default class Month extends React.Component {
290295 ) ;
291296 } ;
292297
298+ handleQuarterNavigation = ( newQuarter , newDate ) => {
299+ if ( this . isDisabled ( newDate ) || this . isExcluded ( newDate ) ) return ;
300+ this . props . setPreSelection ( newDate ) ;
301+ this . QUARTER_REFS [ newQuarter - 1 ] . current &&
302+ this . QUARTER_REFS [ newQuarter - 1 ] . current . focus ( ) ;
303+ } ;
304+
305+ onQuarterKeyDown = ( event , quarter ) => {
306+ const eventKey = event . key ;
307+ if ( ! this . props . disabledKeyboardNavigation ) {
308+ switch ( eventKey ) {
309+ case "Enter" :
310+ this . onQuarterClick ( event , quarter ) ;
311+ this . props . setPreSelection ( this . props . selected ) ;
312+ break ;
313+ case "ArrowRight" :
314+ this . handleQuarterNavigation (
315+ quarter === 4 ? 1 : quarter + 1 ,
316+ utils . addQuarters ( this . props . preSelection , 1 )
317+ ) ;
318+ break ;
319+ case "ArrowLeft" :
320+ this . handleQuarterNavigation (
321+ quarter === 1 ? 4 : quarter - 1 ,
322+ utils . subQuarters ( this . props . preSelection , 1 )
323+ ) ;
324+ break ;
325+ }
326+ }
327+ } ;
328+
293329 getMonthClassNames = ( m ) => {
294330 const {
295331 day,
@@ -343,6 +379,16 @@ export default class Month extends React.Component {
343379 return tabIndex ;
344380 } ;
345381
382+ getQuarterTabIndex = ( q ) => {
383+ const preSelectedQuarter = utils . getQuarter ( this . props . preSelection ) ;
384+ const tabIndex =
385+ ! this . props . disabledKeyboardNavigation && q === preSelectedQuarter
386+ ? "0"
387+ : "-1" ;
388+
389+ return tabIndex ;
390+ } ;
391+
346392 getAriaLabel = ( month ) => {
347393 const {
348394 chooseDayAriaLabelPrefix = "Choose" ,
@@ -360,7 +406,15 @@ export default class Month extends React.Component {
360406 } ;
361407
362408 getQuarterClassNames = ( q ) => {
363- const { day, startDate, endDate, selected, minDate, maxDate } = this . props ;
409+ const {
410+ day,
411+ startDate,
412+ endDate,
413+ selected,
414+ minDate,
415+ maxDate,
416+ preSelection,
417+ } = this . props ;
364418 return classnames (
365419 "react-datepicker__quarter-text" ,
366420 `react-datepicker__quarter-${ q } ` ,
@@ -373,6 +427,8 @@ export default class Month extends React.Component {
373427 q ,
374428 selected
375429 ) ,
430+ "react-datepicker__quarter-text--keyboard-selected" :
431+ utils . getQuarter ( preSelection ) === q ,
376432 "react-datepicker__quarter--in-range" : utils . isQuarterInRange (
377433 startDate ,
378434 endDate ,
@@ -454,12 +510,18 @@ export default class Month extends React.Component {
454510 { quarters . map ( ( q , j ) => (
455511 < div
456512 key = { j }
513+ ref = { this . QUARTER_REFS [ j ] }
457514 role = "option"
458515 onClick = { ( ev ) => {
459516 this . onQuarterClick ( ev , q ) ;
460517 } }
518+ onKeyDown = { ( ev ) => {
519+ this . onQuarterKeyDown ( ev , q ) ;
520+ } }
461521 className = { this . getQuarterClassNames ( q ) }
462522 aria-selected = { this . isSelectedQuarter ( day , q , selected ) }
523+ tabIndex = { this . getQuarterTabIndex ( q ) }
524+ aria-current = { this . isCurrentQuarter ( day , q ) ? "date" : undefined }
463525 >
464526 { utils . getQuarterShortInLocale ( q , this . props . locale ) }
465527 </ div >
0 commit comments