From 388d19e04f83f85abd4602adb04cc71ac575764a Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Mon, 20 Nov 2023 09:19:44 -0500 Subject: [PATCH] fix(datetime): updating value with min scrolls to new value (#28549) Issue number: resolves #28548 --------- ## What is the current behavior? Datetime was not scrolling at all when the `value` prop was changed programmatically. This was due to some logic we had in `componentDidRender` to work around a WebKit bug which was causing the scroll position to be moved back to where it was prior to setting the `value` prop. This caused the scroll position to never move. ## What is the new behavior? - Datetime scrolls to the new value when `value` is updated programmatically even if `min` is set. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `7.5.6-dev.11700169088.140f3e6a` Co-authored-by: amandaejohnston --- core/src/components/datetime/datetime.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index cdf3859715..d2c6cd6d0b 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -1132,7 +1132,7 @@ export class Datetime implements ComponentInterface { * so we need to re-init behavior with the new elements. */ componentDidRender() { - const { presentation, prevPresentation, calendarBodyRef, minParts, preferWheel } = this; + const { presentation, prevPresentation, calendarBodyRef, minParts, preferWheel, forceRenderDate } = this; /** * TODO(FW-2165) @@ -1150,7 +1150,20 @@ export class Datetime implements ComponentInterface { const hasCalendarGrid = !preferWheel && ['date-time', 'time-date', 'date'].includes(presentation); if (minParts !== undefined && hasCalendarGrid && calendarBodyRef) { const workingMonth = calendarBodyRef.querySelector('.calendar-month:nth-of-type(1)'); - if (workingMonth) { + /** + * We need to make sure the datetime is not in the process + * of scrolling to a new datetime value if the value + * is updated programmatically. + * Otherwise, the datetime will appear to not scroll at all because + * we are resetting the scroll position to the center of the view. + * Prior to the datetime's value being updated programmatically, + * the calendarBodyRef is scrolled such that the middle month is centered + * in the view. The below code updates the scroll position so the middle + * month is also centered in the view. Since the scroll position did not change, + * the scroll callback in this file does not fire, + * and the resolveForceDateScrolling promise never resolves. + */ + if (workingMonth && forceRenderDate === undefined) { calendarBodyRef.scrollLeft = workingMonth.clientWidth * (isRTL(this.el) ? -1 : 1); } }