Skip to content

Commit bcafc84

Browse files
Copilotrtivital
andcommitted
Add clarifying comments for better code maintainability
Co-authored-by: rtivital <[email protected]>
1 parent f253442 commit bcafc84

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/@mantine/dates/src/components/DatePicker/DatePicker.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,12 @@ export const DatePicker: DatePickerComponent = factory<DatePickerFactory>((_prop
183183

184184
// Sync navigation date when value changes in controlled mode
185185
useEffect(() => {
186+
// Only update navigation when component is in controlled mode (value !== undefined)
186187
if (value !== undefined) {
187-
// For range arrays, use the first non-null date
188-
const dateToNavigate = Array.isArray(value) ? value.find((d) => d != null) : value;
188+
// For range arrays, use the first non-null/non-undefined date
189+
const dateToNavigate = Array.isArray(value)
190+
? value.find((d) => d != null) // != null checks both null and undefined
191+
: value;
189192
const dateString = toDateString(dateToNavigate);
190193
if (dateString) {
191194
setDateRef.current?.(dateString);

0 commit comments

Comments
 (0)