Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: prevent calendar-compat from crashing when value is undefined",
"packageName": "@fluentui/react-calendar-compat",
"email": "vgenaev@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { Calendar } from './Calendar';
import { isConformant } from '../../testing/isConformant';

Expand All @@ -15,4 +17,13 @@ describe('Calendar', () => {
'component-has-static-classnames-object',
],
});

it('should render without crashing when value is undefined', () => {
expect(() => render(<Calendar value={undefined} />)).not.toThrow();
});

it('should render correctly when value is undefined', () => {
const { container } = render(<Calendar value={undefined} />);
expect(container.querySelector('[role="grid"]')).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const Calendar: React.FunctionComponent<CalendarProps> = React.forwardRef
dateTimeFormatter.formatMonthDayYear(today, strings!),
);
}
if (dateTimeFormatter && strings!.selectedDateFormatString) {
if (dateTimeFormatter && strings!.selectedDateFormatString && selectedDate) {
const dateStringFormatter = monthPickerOnly
? dateTimeFormatter.formatMonthYear
: dateTimeFormatter.formatMonthDayYear;
Expand All @@ -349,8 +349,8 @@ export const Calendar: React.FunctionComponent<CalendarProps> = React.forwardRef
{isDayPickerVisible && (
<CalendarDay
gridLabel={selectionAndTodayString}
selectedDate={selectedDate!}
navigatedDate={navigatedDay!}
selectedDate={selectedDate ?? today}
navigatedDate={navigatedDay ?? today}
today={today}
onSelectDate={onDateSelected}
// eslint-disable-next-line react/jsx-no-bind
Expand Down