Skip to content

Commit 327a033

Browse files
-fix focus logic to work with or without adjacent days;
1 parent b857c1d commit 327a033

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,14 +811,17 @@ export class Datetime implements ComponentInterface {
811811

812812
private focusWorkingDay = (currentMonth: Element) => {
813813
/**
814-
* Get the number of padding days so
814+
* Get the number of offset days so
815815
* we know how much to offset our next selector by
816816
* to grab the correct calendar-day element.
817817
*/
818-
const padding = currentMonth.querySelectorAll('.calendar-day-padding');
819-
const { day, adjacentDay } = this.workingParts;
820818

821-
if (day === null || adjacentDay) {
819+
const { day, month, year } = this.workingParts;
820+
const firstOfMonth = new Date(`${month}/1/${year}`).getDay();
821+
const offset =
822+
firstOfMonth >= this.firstDayOfWeek ? firstOfMonth - (this.firstDayOfWeek) : 7 - (this.firstDayOfWeek - firstOfMonth);
823+
824+
if (day === null) {
822825
return;
823826
}
824827

@@ -827,7 +830,7 @@ export class Datetime implements ComponentInterface {
827830
* and focus it.
828831
*/
829832
const dayEl = currentMonth.querySelector(
830-
`.calendar-day-wrapper:nth-of-type(${padding.length + day}) .calendar-day`
833+
`.calendar-day-wrapper:nth-of-type(${offset + day}) .calendar-day`
831834
) as HTMLElement | null;
832835
if (dayEl) {
833836
dayEl.focus();

0 commit comments

Comments
 (0)