Skip to content

Commit

Permalink
Fix prod build?
Browse files Browse the repository at this point in the history
(cherry picked from commit a8a9271)
  • Loading branch information
stowball committed Jan 8, 2025
1 parent 96ecb7e commit e489448
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
24 changes: 13 additions & 11 deletions packages/react/src/date-picker/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,12 @@ export function CalendarRange({

return (
<td
// @ts-expect-error: Type '(event: KeyboardEvent) => void' is not assignable to type 'KeyboardEventHandler<HTMLTableDataCellElement>'.
onKeyDown={handleKeyDown}
// @ts-expect-error: Type 'RefObject<HTMLButtonElement>' is not assignable to type 'LegacyRef<HTMLTableDataCellElement> | undefined'
ref={buttonRef}
tabIndex={-1}
{...(isHidden ? undefined : interactiveProps)}
onMouseEnter={
onHover && !isHidden
? () => {
clearHoveredDay?.cancel();
onHover(props.date);
}
: undefined
}
onMouseLeave={onHover && !isHidden ? clearHoveredDay : undefined}
// @ts-expect-error: Type '(event: KeyboardEvent) => void' is not assignable to type 'KeyboardEventHandler<HTMLTableDataCellElement>'.
onKeyDown={handleKeyDown}
>
{/* Without this focusable span, left and right do not work in screen readers */}
<span
Expand All @@ -175,6 +166,17 @@ export function CalendarRange({
position: 'absolute',
},
}}
onMouseEnter={() => {
if (onHover && !isHidden) {
clearHoveredDay?.cancel();
onHover(props.date);
}
}}
onMouseLeave={() => {
if (onHover && !isHidden) {
clearHoveredDay?.();
}
}}
tabIndex={-1}
>
{isHidden ? undefined : children}
Expand Down
15 changes: 9 additions & 6 deletions packages/react/src/date-picker/reactDayPickerStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,8 @@ export const reactDayRangePickerStyles = (
'.rdp-day': {
...(inputMode === 'from' && startStyles),
...(inputMode === 'to' && endStyles),
'&:hover:not([disabled])::before': {
...(inputMode === 'from' && startStyles),
...(inputMode === 'to' && endStyles),
...highContrastOutlineStyles,
backgroundColor: boxPalette.backgroundShade,
borderColor: boxPalette.selected,
'&::before': {
borderColor: 'transparent',
borderStyle: 'solid',
borderWidth: tokens.borderWidth.lg,
content: '""',
Expand All @@ -240,6 +236,13 @@ export const reactDayRangePickerStyles = (
position: 'absolute',
zIndex: -1,
},
'&:hover:not([disabled])::before': {
...(inputMode === 'from' && startStyles),
...(inputMode === 'to' && endStyles),
...highContrastOutlineStyles,
backgroundColor: boxPalette.backgroundShade,
borderColor: boxPalette.selected,
},
'&:hover:not([disabled])': {
color: boxPalette.foregroundText,
textDecoration: 'underline',
Expand Down
22 changes: 10 additions & 12 deletions packages/react/src/date-range-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,11 @@ export const DateRangePicker = ({
[value]
);

const [hoveredDay, setHoveredDay] = useState<Date>();
const [hoveredDay, setHoveredDay] = useState<string>();

const onHover = useCallback(
(date: Date) => {
setHoveredDay(date);
},
[setHoveredDay]
);
const onHover = useCallback((date: Date) => {
setHoveredDay(date.toISOString());
}, []);

// From input state
const [fromInputValue, setFromInputValue] = useState(
Expand Down Expand Up @@ -427,7 +424,7 @@ export const DateRangePicker = ({
: valueAsDateOrUndefined.to,
},
modifiers: {
fromRange: (day: Date) => fromRange()[day.toDateString()],
fromRange: (day: Date) => fromRange()[day.toISOString()],
},
modifiersClassNames: {
fromRange: 'range',
Expand Down Expand Up @@ -557,12 +554,13 @@ export function useDateRangePickerIds(idProp?: string) {
return { fieldsetId, fromId, hintId, messageId, toId };
}

const getRange = (startDate?: Date, endDate?: Date) => {
const getRange = (startDate?: Date | string, endDate?: Date | string) => {
const range: Record<string, boolean> = {};
if (startDate && endDate) {
let current = addDays(startDate, 1);
while (current < endDate) {
range[current.toDateString()] = true;
let current = addDays(new Date(startDate), 1);
const endDateAsDate = new Date(endDate);
while (current < endDateAsDate) {
range[current.toISOString()] = true;
current = addDays(current, 1);
}
}
Expand Down

0 comments on commit e489448

Please sign in to comment.