@@ -57,7 +57,6 @@ const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}`
57
57
const EVENT_CLICK_DATA_API = `click${ EVENT_KEY } ${ DATA_API_KEY } `
58
58
59
59
const CLASS_NAME_CALENDAR_CELL = 'calendar-cell'
60
- const CLASS_NAME_CALENDAR_CELL_INNER = 'calendar-cell-inner'
61
60
const CLASS_NAME_CALENDAR_ROW = 'calendar-row'
62
61
const CLASS_NAME_CALENDARS = 'calendars'
63
62
@@ -204,7 +203,7 @@ class Calendar extends BaseComponent {
204
203
}
205
204
206
205
_handleCalendarClick ( event ) {
207
- const target = event . target . classList . contains ( CLASS_NAME_CALENDAR_CELL_INNER ) ? event . target . parentElement : event . target
206
+ const { target } = event
208
207
const date = this . _getDate ( target )
209
208
const cloneDate = new Date ( date )
210
209
const index = Manipulator . getDataAttribute ( target . closest ( SELECTOR_CALENDAR ) , 'calendar-index' )
@@ -271,11 +270,11 @@ class Calendar extends BaseComponent {
271
270
let element = event . target
272
271
273
272
if ( this . _config . selectionType === 'week' && element . tabIndex === - 1 ) {
274
- element = element . closest ( 'tr [tabindex="0"]' )
273
+ element = element . closest ( ` ${ SELECTOR_CALENDAR_ROW } [tabindex="0"]` )
275
274
}
276
275
277
276
const list = SelectorEngine . find (
278
- this . _config . selectionType === 'week' ? 'tr [tabindex="0"]' : 'td [tabindex="0"]' ,
277
+ this . _config . selectionType === 'week' ? ` ${ SELECTOR_CALENDAR_ROW } [tabindex="0"]` : ` ${ SELECTOR_CALENDAR_CELL } [tabindex="0"]` ,
279
278
this . _element
280
279
)
281
280
@@ -304,7 +303,7 @@ class Calendar extends BaseComponent {
304
303
const callback = key => {
305
304
setTimeout ( ( ) => {
306
305
const _list = SelectorEngine . find (
307
- 'td [tabindex="0"], tr [tabindex="0"]' ,
306
+ ` ${ SELECTOR_CALENDAR_CELL } [tabindex="0"], ${ SELECTOR_CALENDAR_ROW } [tabindex="0"]` ,
308
307
SelectorEngine . find ( '.calendar' , this . _element ) . pop ( )
309
308
)
310
309
@@ -356,7 +355,7 @@ class Calendar extends BaseComponent {
356
355
}
357
356
358
357
_handleCalendarMouseEnter ( event ) {
359
- const target = event . target . classList . contains ( CLASS_NAME_CALENDAR_CELL_INNER ) ? event . target . parentElement : event . target
358
+ const { target } = event
360
359
const date = this . _getDate ( target )
361
360
362
361
if ( isDateDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) ) {
@@ -612,32 +611,31 @@ class Calendar extends BaseComponent {
612
611
const listOfYears = createGroupsInArray ( getYears ( calendarDate . getFullYear ( ) ) , 4 )
613
612
const weekDays = monthDetails [ 0 ] . days
614
613
615
- const calendarTable = document . createElement ( 'table' )
614
+ const calendarTable = document . createElement ( 'div' )
615
+ calendarTable . classList . add ( 'calendar-table' )
616
+ calendarTable . role = 'table'
617
+
616
618
calendarTable . innerHTML = `
617
619
${ this . _view === 'days' ? `
618
- <thead >
619
- <tr >
620
+ <div class="calendar-row-group" role="rowgroup" >
621
+ <div class="calendar-header-row" role="row" >
620
622
${ this . _config . showWeekNumber ?
621
- `<th class="calendar-cell">
622
- <div class="calendar-header-cell-inner">
623
- ${ this . _config . weekNumbersLabel ?? '' }
624
- </div>
625
- </th>` : ''
623
+ `<div class="calendar-cell-week-number" role="cell">
624
+ ${ this . _config . weekNumbersLabel ?? '' }
625
+ </div>` : ''
626
626
}
627
627
${ weekDays . map ( ( { date } ) => (
628
- `<th class="calendar-cell" abbr="${ date . toLocaleDateString ( this . _config . locale , { weekday : 'long' } ) } ">
629
- <div class="calendar-header-cell-inner">
628
+ `<div class="calendar-cell-header" role="cell" abbr="${ date . toLocaleDateString ( this . _config . locale , { weekday : 'long' } ) } ">
630
629
${ typeof this . _config . weekdayFormat === 'string' ?
631
630
date . toLocaleDateString ( this . _config . locale , { weekday : this . _config . weekdayFormat } ) :
632
631
date
633
632
. toLocaleDateString ( this . _config . locale , { weekday : 'long' } )
634
633
. slice ( 0 , this . _config . weekdayFormat ) }
635
- </div>
636
- </th>`
634
+ </div>`
637
635
) ) . join ( '' ) }
638
- </tr >
639
- </thead >` : '' }
640
- <tbody >
636
+ </div >
637
+ </div >` : '' }
638
+ <div class="calendar-row-group" role="rowgroup" >
641
639
${ this . _view === 'days' ? monthDetails . map ( week => {
642
640
const date = convertToDateObject (
643
641
week . weekNumber === 0 ?
@@ -646,8 +644,9 @@ class Calendar extends BaseComponent {
646
644
this . _config . selectionType
647
645
)
648
646
return (
649
- `<tr
650
- class="calendar-row ${ this . _config . selectionType === 'week' && this . _sharedClassNames ( date ) } "
647
+ `<div
648
+ class="${ CLASS_NAME_CALENDAR_ROW } ${ this . _config . selectionType === 'week' && this . _sharedClassNames ( date ) } "
649
+ role="row"
651
650
tabindex="${
652
651
this . _config . selectionType === 'week' &&
653
652
week . days . some ( day => day . month === 'current' ) &&
@@ -656,12 +655,13 @@ class Calendar extends BaseComponent {
656
655
${ isDateSelected ( date , this . _startDate , this . _endDate ) ? 'aria-selected="true"' : '' }
657
656
>
658
657
${ this . _config . showWeekNumber ?
659
- `<th class="calendar-cell-week-number">${ week . weekNumber === 0 ? 53 : week . weekNumber } </td >` : ''
658
+ `<div class="calendar-cell-week-number" role="cell" >${ week . weekNumber === 0 ? 53 : week . weekNumber } </div >` : ''
660
659
}
661
660
${ week . days . map ( ( { date, month } ) => (
662
661
month === 'current' || this . _config . showAdjacementDays ?
663
- `<td
664
- class="calendar-cell ${ this . _dayClassNames ( date , month ) } "
662
+ `<div
663
+ role="cell"
664
+ class="${ CLASS_NAME_CALENDAR_CELL } ${ this . _dayClassNames ( date , month ) } "
665
665
tabindex="${
666
666
this . _config . selectionType === 'day' &&
667
667
( month === 'current' || this . _config . selectAdjacementDays ) &&
@@ -670,53 +670,49 @@ class Calendar extends BaseComponent {
670
670
${ isDateSelected ( date , this . _startDate , this . _endDate ) ? 'aria-selected="true"' : '' }
671
671
data-coreui-date="${ date } "
672
672
>
673
- <div class="calendar-cell-inner day">
674
- ${ date . toLocaleDateString ( this . _config . locale , { day : 'numeric' } ) }
675
- </div>
676
- </td>` :
677
- '<td></td>'
678
- ) ) . join ( '' ) } </tr>`
673
+ ${ date . toLocaleDateString ( this . _config . locale , { day : 'numeric' } ) }
674
+ </div>` :
675
+ '<div></div>'
676
+ ) ) . join ( '' ) } </div>`
679
677
)
680
678
} ) . join ( '' ) : '' }
681
679
${ this . _view === 'months' ? listOfMonths . map ( ( row , index ) => (
682
- `<tr >
680
+ `<div class=" ${ CLASS_NAME_CALENDAR_ROW } " role="row" >
683
681
${ row . map ( ( month , idx ) => {
684
682
const date = new Date ( calendarDate . getFullYear ( ) , ( index * 3 ) + idx , 1 )
685
683
return (
686
- `<td
687
- class="calendar-cell ${ this . _sharedClassNames ( date ) } "
684
+ `<div
685
+ class="${ CLASS_NAME_CALENDAR_CELL } ${ this . _sharedClassNames ( date ) } "
688
686
data-coreui-date="${ date . toDateString ( ) } "
687
+ role="cell"
689
688
tabindex="${ isDateDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) ? - 1 : 0 } "
690
689
${ isDateSelected ( date , this . _startDate , this . _endDate ) ? 'aria-selected="true"' : '' }
691
690
>
692
- <div class="calendar-cell-inner month">
693
- ${ month }
694
- </div>
695
- </td>`
691
+ ${ month }
692
+ </div>`
696
693
)
697
694
} ) . join ( '' ) }
698
- </tr >`
695
+ </div >`
699
696
) ) . join ( '' ) : '' }
700
697
${ this . _view === 'years' ? listOfYears . map ( row => (
701
- `<tr >
698
+ `<div class=" ${ CLASS_NAME_CALENDAR_ROW } " role="row" >
702
699
${ row . map ( year => {
703
700
const date = new Date ( year , 0 , 1 )
704
701
return (
705
- `<td
706
- class="calendar-cell ${ this . _sharedClassNames ( date ) } "
702
+ `<div
703
+ class="${ CLASS_NAME_CALENDAR_CELL } ${ this . _sharedClassNames ( date ) } "
707
704
data-coreui-date="${ date . toDateString ( ) } "
705
+ role="cell"
708
706
tabindex="${ isDateDisabled ( date , this . _config . minDate , this . _config . maxDate , this . _config . disabledDates ) ? - 1 : 0 } "
709
707
${ isDateSelected ( date , this . _startDate , this . _endDate ) ? 'aria-selected="true"' : '' }
710
708
>
711
- <div class="calendar-cell-inner year">
712
- ${ year }
713
- </div>
714
- </td>`
709
+ ${ year }
710
+ </div>`
715
711
)
716
712
} ) . join ( '' ) }
717
- </tr >`
713
+ </div >`
718
714
) ) . join ( '' ) : '' }
719
- </tbody >
715
+ </div >
720
716
`
721
717
calendarPanelEl . append ( navigationElement , calendarTable )
722
718
0 commit comments