@@ -50,11 +50,15 @@ import { CALENDAR_HEADER_NEXT_BUTTON, CALENDAR_HEADER_PREVIOUS_BUTTON } from "./
50
50
import type { YearRangePickerChangeEventDetail } from "./YearRangePicker.js" ;
51
51
52
52
interface ICalendarPicker extends HTMLElement {
53
- _showPreviousPage : ( ) => void | Promise < void > ,
54
- _showNextPage : ( ) => void | Promise < void > ,
53
+ _showPreviousPage : ( ) => void ,
54
+ _showNextPage : ( ) => void ,
55
55
_hasPreviousPage : ( ) => boolean ,
56
56
_hasNextPage : ( ) => boolean ,
57
57
_currentYearRange ?: CalendarYearRangeT ,
58
+ _focusableDay ?: HTMLElement ,
59
+ _focusableMonth ?: HTMLElement ,
60
+ _focusableYear ?: HTMLElement ,
61
+ _focusableYearRange ?: HTMLElement ,
58
62
}
59
63
60
64
/**
@@ -334,9 +338,21 @@ class Calendar extends CalendarPart {
334
338
this . _valueIsProcessed = false ;
335
339
}
336
340
337
- async _focusCurrentPicker ( ) {
338
- await renderFinished ( ) ;
339
- this . _currentPickerDOM . focus ( ) ;
341
+ _focusCurrentPicker ( ) {
342
+ // focus after the current picker's DOM is updated
343
+ requestAnimationFrame ( ( ) => {
344
+ const focusableElement = this . _currentPickerDOM . _focusableDay
345
+ || this . _currentPickerDOM . _focusableMonth
346
+ || this . _currentPickerDOM . _focusableYear
347
+ || this . _currentPickerDOM . _focusableYearRange ;
348
+
349
+ if ( focusableElement ) {
350
+ focusableElement . focus ( ) ;
351
+ } else {
352
+ // focus the picker container if no focusable element is found
353
+ this . _currentPickerDOM . focus ( ) ;
354
+ }
355
+ } ) ;
340
356
}
341
357
342
358
/**
@@ -527,40 +543,40 @@ class Calendar extends CalendarPart {
527
543
/**
528
544
* The user clicked the "month" button in the header
529
545
*/
530
- async onHeaderShowMonthPress ( ) {
531
- await this . showMonth ( ) ;
546
+ onHeaderShowMonthPress ( ) {
547
+ this . showMonth ( ) ;
532
548
this . fireDecoratorEvent ( "show-month-view" ) ;
533
549
}
534
550
535
- async showMonth ( ) {
551
+ showMonth ( ) {
536
552
this . _currentPicker = "month" ;
537
- await this . _focusCurrentPicker ( ) ;
553
+ this . _focusCurrentPicker ( ) ;
538
554
}
539
555
540
556
/**
541
557
* The user clicked the "year" button in the header
542
558
*/
543
- async onHeaderShowYearPress ( ) {
544
- await this . showYear ( ) ;
559
+ onHeaderShowYearPress ( ) {
560
+ this . showYear ( ) ;
545
561
this . fireDecoratorEvent ( "show-year-view" ) ;
546
562
}
547
563
548
- async showYear ( ) {
564
+ showYear ( ) {
549
565
this . _currentPicker = "year" ;
550
- await this . _focusCurrentPicker ( ) ;
566
+ this . _focusCurrentPicker ( ) ;
551
567
}
552
568
553
569
/**
554
570
* The user clicked the "year range" button in the YearPicker header
555
571
*/
556
- async onHeaderShowYearRangePress ( ) {
557
- await this . showYearRange ( ) ;
572
+ onHeaderShowYearRangePress ( ) {
573
+ this . showYearRange ( ) ;
558
574
this . fireDecoratorEvent ( "show-year-range-view" ) ;
559
575
}
560
576
561
- async showYearRange ( ) {
577
+ showYearRange ( ) {
562
578
this . _currentPicker = "yearrange" ;
563
- await this . _focusCurrentPicker ( ) ;
579
+ this . _focusCurrentPicker ( ) ;
564
580
}
565
581
566
582
get _currentPickerDOM ( ) {
@@ -705,35 +721,35 @@ class Calendar extends CalendarPart {
705
721
this . _fireEventAndUpdateSelectedDates ( e . detail . dates ) ;
706
722
}
707
723
708
- async onSelectedMonthChange ( e : CustomEvent < MonthPickerChangeEventDetail > ) {
724
+ onSelectedMonthChange ( e : CustomEvent < MonthPickerChangeEventDetail > ) {
709
725
this . timestamp = e . detail . timestamp ;
710
726
711
727
if ( this . _pickersMode === CalendarPickersMode . DAY_MONTH_YEAR ) {
712
728
this . _currentPicker = "day" ;
713
- await this . _focusCurrentPicker ( ) ;
729
+ this . _focusCurrentPicker ( ) ;
714
730
} else {
715
731
this . _fireEventAndUpdateSelectedDates ( e . detail . dates ) ;
716
732
}
717
733
}
718
734
719
- async onSelectedYearChange ( e : CustomEvent < YearPickerChangeEventDetail > ) {
735
+ onSelectedYearChange ( e : CustomEvent < YearPickerChangeEventDetail > ) {
720
736
this . timestamp = e . detail . timestamp ;
721
737
722
738
if ( this . _pickersMode === CalendarPickersMode . DAY_MONTH_YEAR ) {
723
739
this . _currentPicker = "day" ;
724
- await this . _focusCurrentPicker ( ) ;
740
+ this . _focusCurrentPicker ( ) ;
725
741
} else if ( this . _pickersMode === CalendarPickersMode . MONTH_YEAR ) {
726
742
this . _currentPicker = "month" ;
727
- await this . _focusCurrentPicker ( ) ;
743
+ this . _focusCurrentPicker ( ) ;
728
744
} else {
729
745
this . _fireEventAndUpdateSelectedDates ( e . detail . dates ) ;
730
746
}
731
747
}
732
748
733
- async onSelectedYearRangeChange ( e : CustomEvent < YearRangePickerChangeEventDetail > ) {
749
+ onSelectedYearRangeChange ( e : CustomEvent < YearRangePickerChangeEventDetail > ) {
734
750
this . timestamp = e . detail . timestamp ;
735
751
this . _currentPicker = "year" ;
736
- await this . _focusCurrentPicker ( ) ;
752
+ this . _focusCurrentPicker ( ) ;
737
753
}
738
754
739
755
onNavigate ( e : CustomEvent ) {
0 commit comments