@@ -13,8 +13,14 @@ import CalendarDate from "@ui5/webcomponents-localization/dist/dates/CalendarDat
13
13
import calculateWeekNumber from "@ui5/webcomponents-localization/dist/dates/calculateWeekNumber.js" ;
14
14
import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js" ;
15
15
import ItemNavigationBehavior from "@ui5/webcomponents-base/dist/types/ItemNavigationBehavior.js" ;
16
+ import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
16
17
import DayPickerTemplate from "./generated/templates/DayPickerTemplate.lit.js" ;
17
18
19
+ import {
20
+ DAY_PICKER_WEEK_NUMBER_TEXT ,
21
+ DAY_PICKER_NON_WORKING_DAY ,
22
+ } from "./generated/i18n/i18n-defaults.js" ;
23
+
18
24
// Styles
19
25
import dayPickerCSS from "./generated/themes/DayPicker.css.js" ;
20
26
@@ -134,15 +140,6 @@ const metadata = {
134
140
multiple : true ,
135
141
} ,
136
142
137
- /**
138
- * @type {Object }
139
- * @private
140
- */
141
- _weekNumbers : {
142
- type : Object ,
143
- multiple : true ,
144
- } ,
145
-
146
143
/**
147
144
* @type {boolean }
148
145
* @private
@@ -229,6 +226,8 @@ class DayPicker extends UI5Element {
229
226
"PageTop" ,
230
227
this . _handleMonthTopOverflow . bind ( this )
231
228
) ;
229
+
230
+ this . i18nBundle = getI18nBundle ( "@ui5/webcomponents" ) ;
232
231
}
233
232
234
233
onBeforeRendering ( ) {
@@ -243,6 +242,8 @@ class DayPicker extends UI5Element {
243
242
let week = [ ] ;
244
243
this . _weekNumbers = [ ] ;
245
244
let weekday ;
245
+ const _monthsNameWide = this . _oLocaleData . getMonths ( "wide" , this . _calendarDate . _oUDate . sCalendarType ) ;
246
+
246
247
if ( this . minDate ) {
247
248
this . _minDateObject = new Date ( this . _minDate ) ;
248
249
}
@@ -260,6 +261,9 @@ class DayPicker extends UI5Element {
260
261
if ( weekday < 0 ) {
261
262
weekday += 7 ;
262
263
}
264
+
265
+ const nonWorkingAriaLabel = this . _isWeekend ( oCalDate ) ? `${ this . _dayPickerNonWorkingDay } ` : "" ;
266
+
263
267
day = {
264
268
timestamp : timestamp . toString ( ) ,
265
269
selected : this . _selectedDates . some ( d => {
@@ -271,16 +275,9 @@ class DayPicker extends UI5Element {
271
275
iDay : oCalDate . getDate ( ) ,
272
276
_index : i . toString ( ) ,
273
277
classes : `ui5-dp-item ui5-dp-wday${ weekday } ` ,
278
+ ariaLabel : `${ nonWorkingAriaLabel } ${ _monthsNameWide [ oCalDate . getMonth ( ) ] } ${ oCalDate . getDate ( ) } , ${ oCalDate . getYear ( ) } ` ,
274
279
} ;
275
280
276
- const weekNumber = calculateWeekNumber ( getFirstDayOfWeek ( ) , oCalDate . toUTCJSDate ( ) , oCalDate . getYear ( ) , this . _oLocale , this . _oLocaleData ) ;
277
-
278
- if ( lastWeekNumber !== weekNumber ) {
279
- this . _weekNumbers . push ( weekNumber ) ;
280
-
281
- lastWeekNumber = weekNumber ;
282
- }
283
-
284
281
const isToday = oCalDate . isSame ( CalendarDate . fromLocalJSDate ( new Date ( ) , this . _primaryCalendarType ) ) ;
285
282
286
283
week . push ( day ) ;
@@ -301,10 +298,12 @@ class DayPicker extends UI5Element {
301
298
if ( isToday ) {
302
299
day . classes += " ui5-dp-item--now" ;
303
300
todayIndex = i ;
301
+ day . ariaLabel = `today ${ day . ariaLabel } ` ;
304
302
}
305
303
306
304
if ( oCalDate . getMonth ( ) !== this . _month ) {
307
305
day . classes += " ui5-dp-item--othermonth" ;
306
+ day . ariaDisabled = "true" ;
308
307
}
309
308
310
309
day . id = `${ this . _id } -${ timestamp } ` ;
@@ -317,8 +316,20 @@ class DayPicker extends UI5Element {
317
316
day . disabled = true ;
318
317
}
319
318
319
+ this . _hideWeekNumbers = this . shouldHideWeekNumbers ;
320
+
320
321
if ( day . classes . indexOf ( "ui5-dp-wday6" ) !== - 1
321
322
|| _aVisibleDays . length - 1 === i ) {
323
+ const weekNumber = calculateWeekNumber ( getFirstDayOfWeek ( ) , oCalDate . toUTCJSDate ( ) , oCalDate . getYear ( ) , this . _oLocale , this . _oLocaleData ) ;
324
+ if ( lastWeekNumber !== weekNumber ) {
325
+ const weekNum = {
326
+ weekNum : weekNumber ,
327
+ isHidden : this . _hideWeekNumbers ,
328
+ } ;
329
+ week . unshift ( weekNum ) ;
330
+ lastWeekNumber = weekNumber ;
331
+ }
332
+
322
333
this . _weeks . push ( week ) ;
323
334
week = [ ] ;
324
335
}
@@ -338,6 +349,10 @@ class DayPicker extends UI5Element {
338
349
let dayName ;
339
350
340
351
this . _dayNames = [ ] ;
352
+ this . _dayNames . push ( {
353
+ classes : "ui5-dp-dayname" ,
354
+ name : this . _dayPickerWeekNumberText ,
355
+ } ) ;
341
356
for ( let i = 0 ; i < 7 ; i ++ ) {
342
357
weekday = i + this . _getFirstDayOfWeek ( ) ;
343
358
if ( weekday > 6 ) {
@@ -353,8 +368,7 @@ class DayPicker extends UI5Element {
353
368
this . _dayNames . push ( dayName ) ;
354
369
}
355
370
356
- this . _dayNames [ 0 ] . classes += " ui5-dp-firstday" ;
357
- this . _hideWeekNumbers = this . shouldHideWeekNumbers ;
371
+ this . _dayNames [ 1 ] . classes += " ui5-dp-firstday" ;
358
372
}
359
373
360
374
onAfterRendering ( ) {
@@ -489,13 +503,21 @@ class DayPicker extends UI5Element {
489
503
const focusableDays = [ ] ;
490
504
491
505
for ( let i = 0 ; i < this . _weeks . length ; i ++ ) {
492
- const week = this . _weeks [ i ] . filter ( x => ! x . disabled ) ;
506
+ const week = this . _weeks [ i ] . slice ( 1 ) . filter ( x => ! x . disabled ) ;
493
507
focusableDays . push ( week ) ;
494
508
}
495
509
496
510
return [ ] . concat ( ...focusableDays ) ;
497
511
}
498
512
513
+ get _dayPickerWeekNumberText ( ) {
514
+ return this . i18nBundle . getText ( DAY_PICKER_WEEK_NUMBER_TEXT ) ;
515
+ }
516
+
517
+ get _dayPickerNonWorkingDay ( ) {
518
+ return this . i18nBundle . getText ( DAY_PICKER_NON_WORKING_DAY ) ;
519
+ }
520
+
499
521
_modifySelectionAndNotifySubscribers ( sNewDate , bAdd ) {
500
522
if ( bAdd ) {
501
523
this . selectedDates = [ ...this . _selectedDates , sNewDate ] ;
@@ -737,6 +759,7 @@ class DayPicker extends UI5Element {
737
759
static async onDefine ( ) {
738
760
await Promise . all ( [
739
761
fetchCldr ( getLocale ( ) . getLanguage ( ) , getLocale ( ) . getRegion ( ) , getLocale ( ) . getScript ( ) ) ,
762
+ fetchI18nBundle ( "@ui5/webcomponents" ) ,
740
763
] ) ;
741
764
}
742
765
}
0 commit comments