@@ -20,6 +20,7 @@ import {
2020 strAsDate ,
2121} from '../utils/calendar/helpers' ;
2222import { captureCSSForPortal } from '../utils/calendar/cssVariables' ;
23+ import ResizeDetector from '../utils/ResizeDetector' ;
2324import '../components/css/datepickers.css' ;
2425
2526const DatePickerRange = ( {
@@ -104,6 +105,8 @@ const DatePickerRange = ({
104105 const containerRef = useRef < HTMLDivElement > ( null ) ;
105106 const startInputRef = useRef < HTMLInputElement | null > ( null ) ;
106107 const endInputRef = useRef < HTMLInputElement | null > ( null ) ;
108+ const startAutosizeRef = useRef < any > ( null ) ;
109+ const endAutosizeRef = useRef < any > ( null ) ;
107110 const calendarRef = useRef < CalendarHandle > ( null ) ;
108111 const hasPortal = with_portal || with_full_screen_portal ;
109112
@@ -128,6 +131,19 @@ const DatePickerRange = ({
128131 setEndInputValue ( formatDate ( internalEndDate , display_format ) ) ;
129132 } , [ internalEndDate , display_format ] ) ;
130133
134+ const handleResize = useCallback ( ( ) => {
135+ startAutosizeRef . current ?. updateInputWidth ?.( ) ;
136+ endAutosizeRef . current ?. updateInputWidth ?.( ) ;
137+ } , [ ] ) ;
138+
139+ useEffect ( ( ) => {
140+ startAutosizeRef . current ?. updateInputWidth ?.( ) ;
141+ } , [ startInputValue ] ) ;
142+
143+ useEffect ( ( ) => {
144+ endAutosizeRef . current ?. updateInputWidth ?.( ) ;
145+ } , [ endInputValue ] ) ;
146+
131147 useEffect ( ( ) => {
132148 // Controls when setProps is called. Basically, whenever internal state
133149 // diverges from props (i.e., user interaction)
@@ -313,6 +329,10 @@ const DatePickerRange = ({
313329 ) ;
314330
315331 return (
332+ < ResizeDetector
333+ onResize = { handleResize }
334+ targets = { [ containerRef ] }
335+ >
316336 < div className = "dash-datepicker" ref = { containerRef } >
317337 < Popover . Root
318338 open = { ! disabled && isCalendarOpen }
@@ -335,6 +355,7 @@ const DatePickerRange = ({
335355 } }
336356 >
337357 < AutosizeInput
358+ ref = { startAutosizeRef }
338359 inputRef = { node => {
339360 startInputRef . current = node ;
340361 } }
@@ -356,6 +377,7 @@ const DatePickerRange = ({
356377 />
357378 < ArrowIcon className = "dash-datepicker-range-arrow" />
358379 < AutosizeInput
380+ ref = { endAutosizeRef }
359381 inputRef = { node => {
360382 endInputRef . current = node ;
361383 } }
@@ -458,6 +480,7 @@ const DatePickerRange = ({
458480 </ Popover . Portal >
459481 </ Popover . Root >
460482 </ div >
483+ </ ResizeDetector >
461484 ) ;
462485} ;
463486
0 commit comments