Skip to content

Commit 9cedfcd

Browse files
refactor(datetime): use key to preserve calendar body ref node (#25838)
1 parent 41e3387 commit 9cedfcd

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

core/src/components/datetime/datetime.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -629,18 +629,8 @@ export class Datetime implements ComponentInterface {
629629
return presentation === 'date' || presentation === 'date-time' || presentation === 'time-date';
630630
}
631631

632-
/**
633-
* Stencil sometimes sets calendarBodyRef to null on rerender, even though
634-
* the element is present. Query for it manually as a fallback.
635-
*
636-
* TODO(FW-901) Remove when issue is resolved: https://github.com/ionic-team/stencil/issues/3253
637-
*/
638-
private getCalendarBodyEl = () => {
639-
return this.calendarBodyRef || this.el.shadowRoot?.querySelector('.calendar-body');
640-
};
641-
642632
private initializeKeyboardListeners = () => {
643-
const calendarBodyRef = this.getCalendarBodyEl();
633+
const calendarBodyRef = this.calendarBodyRef;
644634
if (!calendarBodyRef) {
645635
return;
646636
}
@@ -818,7 +808,7 @@ export class Datetime implements ComponentInterface {
818808
};
819809

820810
private initializeCalendarListener = () => {
821-
const calendarBodyRef = this.getCalendarBodyEl();
811+
const calendarBodyRef = this.calendarBodyRef;
822812
if (!calendarBodyRef) {
823813
return;
824814
}
@@ -1241,7 +1231,7 @@ export class Datetime implements ComponentInterface {
12411231
};
12421232

12431233
private nextMonth = () => {
1244-
const calendarBodyRef = this.getCalendarBodyEl();
1234+
const calendarBodyRef = this.calendarBodyRef;
12451235
if (!calendarBodyRef) {
12461236
return;
12471237
}
@@ -1261,7 +1251,7 @@ export class Datetime implements ComponentInterface {
12611251
};
12621252

12631253
private prevMonth = () => {
1264-
const calendarBodyRef = this.getCalendarBodyEl();
1254+
const calendarBodyRef = this.calendarBodyRef;
12651255
if (!calendarBodyRef) {
12661256
return;
12671257
}
@@ -1989,7 +1979,7 @@ export class Datetime implements ComponentInterface {
19891979
}
19901980
private renderCalendar(mode: Mode) {
19911981
return (
1992-
<div class="datetime-calendar">
1982+
<div class="datetime-calendar" key="datetime-calendar">
19931983
{this.renderCalendarHeader(mode)}
19941984
{this.renderCalendarBody()}
19951985
</div>

0 commit comments

Comments
 (0)