-
Notifications
You must be signed in to change notification settings - Fork 79
fix(date-picker): restore focus on date when navigating month with arrow/page keys #9063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
cf783a2
ca378fb
e437f2d
13edf90
58fb361
78a685a
8458e01
c381edc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,13 +229,8 @@ export class DatePickerMonth { | |
}), | ||
]; | ||
|
||
const weeks: Day[][] = []; | ||
for (let i = 0; i < days.length; i += 7) { | ||
weeks.push(days.slice(i, i + 7)); | ||
} | ||
|
||
return ( | ||
<Host onFocusOut={this.disableActiveFocus} onKeyDown={this.keyDownHandler}> | ||
<Host onFocusout={this.disableActiveFocus} onKeyDown={this.keyDownHandler}> | ||
<div class="calendar" role="grid"> | ||
<div class="week-headers" role="row"> | ||
{adjustedWeekDays.map((weekday) => ( | ||
|
@@ -244,11 +239,10 @@ export class DatePickerMonth { | |
</span> | ||
))} | ||
</div> | ||
{weeks.map((days) => ( | ||
<div class="week-days" role="row"> | ||
{days.map((day) => this.renderDateDay(day))} | ||
</div> | ||
))} | ||
|
||
<div class="week-days" role="row"> | ||
{days.map((day, index) => this.renderDateDay(day, index))} | ||
</div> | ||
</div> | ||
</Host> | ||
); | ||
|
@@ -440,15 +434,16 @@ export class DatePickerMonth { | |
* @param active.day | ||
* @param active.dayInWeek | ||
* @param active.ref | ||
* @param key | ||
*/ | ||
private renderDateDay({ active, currentMonth, date, day, dayInWeek, ref }: Day) { | ||
private renderDateDay({ active, currentMonth, date, day, dayInWeek, ref }: Day, key: number) { | ||
const isFocusedOnStart = this.isFocusedOnStart(); | ||
const isHoverInRange = | ||
this.isHoverInRange() || | ||
(!this.endDate && this.hoverRange && sameDate(this.hoverRange?.end, this.startDate)); | ||
|
||
return ( | ||
<div class="day" key={date.toDateString()} role="gridcell"> | ||
<div class="day" key={key} role="gridcell"> | ||
<calcite-date-picker-day | ||
active={active} | ||
class={{ | ||
|
@@ -473,10 +468,10 @@ export class DatePickerMonth { | |
startOfRange={this.isStartOfRange(date)} | ||
value={date} | ||
// eslint-disable-next-line react/jsx-sort-props -- ref should be last so node attrs/props are in sync (see https://github.com/Esri/calcite-design-system/pull/6530) | ||
ref={(el: HTMLCalciteDatePickerDayElement) => { | ||
ref={async (el: HTMLCalciteDatePickerDayElement) => { | ||
// when moving via keyboard, focus must be updated on active date | ||
if (ref && active && this.activeFocus) { | ||
el?.focus(); | ||
await el?.setFocus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you need to await this? Is ref waiting for the setFocus method to be finished for something? Just trying to understand the need for the ref callback to be async. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, It doesn't need to be async. |
||
} | ||
}} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be set to a spacing variable?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is covered in the tokenization PR here