diff --git a/packages/@react-aria/calendar/src/useCalendarCell.ts b/packages/@react-aria/calendar/src/useCalendarCell.ts index fa7c422987b..aabeac2f9a5 100644 --- a/packages/@react-aria/calendar/src/useCalendarCell.ts +++ b/packages/@react-aria/calendar/src/useCalendarCell.ts @@ -28,7 +28,12 @@ export interface AriaCalendarCellProps { * Whether the cell is disabled. By default, this is determined by the * Calendar's `minValue`, `maxValue`, and `isDisabled` props. */ - isDisabled?: boolean + isDisabled?: boolean, + + /** + * Whether the cell is outside of the current month. + */ + isOutsideMonth?: boolean } export interface CalendarCellAria { @@ -85,7 +90,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta timeZone: state.timeZone }); let isSelected = state.isSelected(date); - let isFocused = state.isCellFocused(date); + let isFocused = state.isCellFocused(date) && !props.isOutsideMonth; isDisabled = isDisabled || state.isCellDisabled(date); let isUnavailable = state.isCellUnavailable(date); let isSelectable = !isDisabled && !isUnavailable; diff --git a/packages/react-aria-components/src/Calendar.tsx b/packages/react-aria-components/src/Calendar.tsx index f3ed804b892..dd4f683a29a 100644 --- a/packages/react-aria-components/src/Calendar.tsx +++ b/packages/react-aria-components/src/Calendar.tsx @@ -496,9 +496,11 @@ export const CalendarCell = /*#__PURE__*/ (forwardRef as forwardRefType)(functio let rangeCalendarState = useContext(RangeCalendarStateContext); let state = calendarState ?? rangeCalendarState!; let {startDate: currentMonth} = useContext(InternalCalendarGridContext) ?? {startDate: state.visibleRange.start}; + let isOutsideMonth = !isSameMonth(currentMonth, date); + let buttonRef = useRef(null); let {cellProps, buttonProps, ...states} = useCalendarCell( - {date}, + {date, isOutsideMonth}, state, buttonRef ); @@ -506,7 +508,6 @@ export const CalendarCell = /*#__PURE__*/ (forwardRef as forwardRefType)(functio let {hoverProps, isHovered} = useHover({...otherProps, isDisabled: states.isDisabled}); let {focusProps, isFocusVisible} = useFocusRing(); isFocusVisible &&= states.isFocused; - let isOutsideMonth = !isSameMonth(currentMonth, date); let isSelectionStart = false; let isSelectionEnd = false; if ('highlightedRange' in state && state.highlightedRange) { diff --git a/packages/react-aria-components/stories/Calendar.stories.tsx b/packages/react-aria-components/stories/Calendar.stories.tsx index e8f0b2158f1..77cc60d7d60 100644 --- a/packages/react-aria-components/stories/Calendar.stories.tsx +++ b/packages/react-aria-components/stories/Calendar.stories.tsx @@ -72,10 +72,10 @@ export const CalendarMultiMonth = () => (
- {date => ({display: isOutsideMonth ? 'none' : '', textAlign: 'center', cursor: 'default', background: isSelected ? 'blue' : ''})} />} + {date => ({opacity: isOutsideMonth ? '0.5' : '', textAlign: 'center', cursor: 'default', background: isSelected ? 'blue' : ''})} />} - {date => ({display: isOutsideMonth ? 'none' : '', textAlign: 'center', cursor: 'default', background: isSelected ? 'blue' : ''})} />} + {date => ({opacity: isOutsideMonth ? '0.5' : '', textAlign: 'center', cursor: 'default', background: isSelected ? 'blue' : ''})} />}