From 9c5a17ece2e2d1af494f6e49bed5ae01435829d3 Mon Sep 17 00:00:00 2001 From: Adrian Borrmann Date: Thu, 12 Mar 2026 11:03:36 -0600 Subject: [PATCH] Run linter on Datepickers --- .../src/fragments/DatePickerRange.tsx | 293 +++++++++--------- .../src/fragments/DatePickerSingle.tsx | 227 +++++++------- 2 files changed, 261 insertions(+), 259 deletions(-) diff --git a/components/dash-core-components/src/fragments/DatePickerRange.tsx b/components/dash-core-components/src/fragments/DatePickerRange.tsx index 919c6b32b7..86f4b52607 100644 --- a/components/dash-core-components/src/fragments/DatePickerRange.tsx +++ b/components/dash-core-components/src/fragments/DatePickerRange.tsx @@ -329,157 +329,158 @@ const DatePickerRange = ({ ); return ( - -
- - -
{ - e.preventDefault(); - if (!isCalendarOpen && !disabled) { - setIsCalendarOpen(true); - } - }} - > - { - startInputRef.current = node; - }} - type="text" - id={start_date_id || accessibleId} - inputClassName="dash-datepicker-input dash-datepicker-start-date" - value={startInputValue} - onChange={e => setStartInputValue(e.target?.value)} - onKeyDown={handleStartInputKeyDown} - onFocus={() => { - if (isCalendarOpen) { - sendStartInputAsDate(); + +
+ + +
{ + e.preventDefault(); + if (!isCalendarOpen && !disabled) { + setIsCalendarOpen(true); } }} - placeholder={start_date_placeholder_text} - disabled={disabled} - dir={direction} - aria-label={start_date_placeholder_text} - /> - - { - endInputRef.current = node; - }} - type="text" - id={end_date_id || accessibleId + '-end-date'} - inputClassName="dash-datepicker-input dash-datepicker-end-date" - value={endInputValue} - onChange={e => setEndInputValue(e.target?.value)} - onKeyDown={handleEndInputKeyDown} - onFocus={() => { - if (isCalendarOpen) { - sendEndInputAsDate(); + > + { + startInputRef.current = node; + }} + type="text" + id={start_date_id || accessibleId} + inputClassName="dash-datepicker-input dash-datepicker-start-date" + value={startInputValue} + onChange={e => + setStartInputValue(e.target?.value) } - }} - placeholder={end_date_placeholder_text} - disabled={disabled} - dir={direction} - aria-label={end_date_placeholder_text} - /> - {clearable && !disabled && ( - - - - )} - -
-
- - - e.preventDefault() - : undefined - } - onOpenAutoFocus={e => e.preventDefault()} - onCloseAutoFocus={e => { - e.preventDefault(); - // Only focus if focus is not already on one of the inputs - const inputs: (Element | null)[] = [ - startInputRef.current, - endInputRef.current, - ]; - if (inputs.includes(document.activeElement)) { - return; + onKeyDown={handleStartInputKeyDown} + onFocus={() => { + if (isCalendarOpen) { + sendStartInputAsDate(); + } + }} + placeholder={start_date_placeholder_text} + disabled={disabled} + dir={direction} + aria-label={start_date_placeholder_text} + /> + + { + endInputRef.current = node; + }} + type="text" + id={end_date_id || accessibleId + '-end-date'} + inputClassName="dash-datepicker-input dash-datepicker-end-date" + value={endInputValue} + onChange={e => + setEndInputValue(e.target?.value) + } + onKeyDown={handleEndInputKeyDown} + onFocus={() => { + if (isCalendarOpen) { + sendEndInputAsDate(); + } + }} + placeholder={end_date_placeholder_text} + disabled={disabled} + dir={direction} + aria-label={end_date_placeholder_text} + /> + {clearable && !disabled && ( + + + + )} + +
+ + + + e.preventDefault() + : undefined } + onOpenAutoFocus={e => e.preventDefault()} + onCloseAutoFocus={e => { + e.preventDefault(); + // Only focus if focus is not already on one of the inputs + const inputs: (Element | null)[] = [ + startInputRef.current, + endInputRef.current, + ]; + if (inputs.includes(document.activeElement)) { + return; + } - // Keeps focus on the component when the calendar closes - if (!startInputValue) { - startInputRef.current?.focus(); - } else { - endInputRef.current?.focus(); - } - }} - > - {with_full_screen_portal && ( - - )} - - - - -
+ // Keeps focus on the component when the calendar closes + if (!startInputValue) { + startInputRef.current?.focus(); + } else { + endInputRef.current?.focus(); + } + }} + > + {with_full_screen_portal && ( + + )} + + + +
+
); }; diff --git a/components/dash-core-components/src/fragments/DatePickerSingle.tsx b/components/dash-core-components/src/fragments/DatePickerSingle.tsx index eff91e6515..527e654b0d 100644 --- a/components/dash-core-components/src/fragments/DatePickerSingle.tsx +++ b/components/dash-core-components/src/fragments/DatePickerSingle.tsx @@ -93,7 +93,6 @@ const DatePickerSingle = ({ autosizeRef.current?.updateInputWidth?.(); }, []); - useEffect(() => { autosizeRef.current?.updateInputWidth?.(); }, [inputValue]); @@ -169,124 +168,126 @@ const DatePickerSingle = ({ return ( -
- - -
{ - e.preventDefault(); - if (!isCalendarOpen && !disabled) { - setIsCalendarOpen(true); - } - }} - > - { - inputRef.current = node; +
+ + +
{ + e.preventDefault(); + if (!isCalendarOpen && !disabled) { + setIsCalendarOpen(true); + } }} - type="text" - id={accessibleId} - inputClassName="dash-datepicker-input dash-datepicker-end-date" - value={inputValue} - onChange={e => setInputValue(e.target?.value)} - onKeyDown={handleInputKeyDown} - placeholder={placeholder} - disabled={disabled} - dir={direction} - aria-label={placeholder} - /> - {clearable && !disabled && !!date && ( - - - - )} + > + { + inputRef.current = node; + }} + type="text" + id={accessibleId} + inputClassName="dash-datepicker-input dash-datepicker-end-date" + value={inputValue} + onChange={e => setInputValue(e.target?.value)} + onKeyDown={handleInputKeyDown} + placeholder={placeholder} + disabled={disabled} + dir={direction} + aria-label={placeholder} + /> + {clearable && !disabled && !!date && ( + + + + )} - -
-
+ +
+ - - e.preventDefault() - : undefined - } - onOpenAutoFocus={e => e.preventDefault()} - onCloseAutoFocus={e => { - e.preventDefault(); - // Only focus if focus is not already on the input - if (document.activeElement !== inputRef.current) { - inputRef.current?.focus(); - } - }} + - {with_full_screen_portal && ( - - )} - { - if (!selection) { - return; - } - setInternalDate(selection); - if (!stay_open_on_select) { - setIsCalendarOpen(false); + e.preventDefault() + : undefined + } + onOpenAutoFocus={e => e.preventDefault()} + onCloseAutoFocus={e => { + e.preventDefault(); + // Only focus if focus is not already on the input + if ( + document.activeElement !== inputRef.current + ) { + inputRef.current?.focus(); } }} - /> - - - -
+ > + {with_full_screen_portal && ( + + )} + { + if (!selection) { + return; + } + setInternalDate(selection); + if (!stay_open_on_select) { + setIsCalendarOpen(false); + } + }} + /> + + +
+
); };