Skip to content

Commit e94e364

Browse files
richardbannRichard Bannyihuiliao
authored
Add test and fix for #5692 (#7455)
In Calendar, selecting an unavailable date with keyboard selected the previous available date. Now it does not change the selection. Co-authored-by: Richard Bann <[email protected]> Co-authored-by: Yihui Liao <[email protected]>
1 parent cd4da2b commit e94e364

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/@react-stately/calendar/src/useCalendarState.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ export function useCalendarState<T extends DateValue = DateValue>(props: Calenda
291291
}
292292
},
293293
selectFocusedDate() {
294-
setValue(focusedDate);
294+
if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {
295+
setValue(focusedDate);
296+
}
295297
},
296298
selectDate(date) {
297299
setValue(date);

packages/react-aria-components/test/Calendar.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,12 @@ describe('Calendar', () => {
342342
expect(cell).not.toHaveAttribute('data-selected');
343343
expect(cell).not.toHaveClass('selected');
344344
});
345+
346+
it('should not modify selection when trying to select an unavailable date by keyboard', async () => {
347+
let calendar = renderCalendar({isDateUnavailable: d => d.day === 15});
348+
let day16 = calendar.getByText('16');
349+
fireEvent.click(day16);
350+
await user.keyboard('[ArrowLeft][Enter]');
351+
expect(calendar.getByLabelText(/selected/)).toBe(day16);
352+
});
345353
});

0 commit comments

Comments
 (0)