Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add onDayPointerEnter, onDayPointerLeave props #1614

Merged
merged 1 commit into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const tests: [EventName, DayEventName][] = [
['onBlur', 'onDayBlur'],
['onMouseEnter', 'onDayMouseEnter'],
['onMouseLeave', 'onDayMouseLeave'],
['onPointerEnter', 'onDayPointerEnter'],
['onPointerLeave', 'onDayPointerLeave'],
['onTouchEnd', 'onDayTouchEnd'],
['onTouchCancel', 'onDayTouchCancel'],
['onTouchMove', 'onDayTouchMove'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
HTMLProps,
KeyboardEventHandler,
MouseEventHandler,
PointerEventHandler,
TouchEventHandler
} from 'react';

Expand All @@ -24,6 +25,8 @@ export type EventName =
| 'onKeyUp'
| 'onMouseEnter'
| 'onMouseLeave'
| 'onPointerEnter'
| 'onPointerLeave'
| 'onTouchCancel'
| 'onTouchEnd'
| 'onTouchMove'
Expand All @@ -37,6 +40,8 @@ export type DayEventName =
| 'onDayKeyUp'
| 'onDayMouseEnter'
| 'onDayMouseLeave'
| 'onDayPointerEnter'
| 'onDayPointerLeave'
| 'onDayTouchCancel'
| 'onDayTouchEnd'
| 'onDayTouchMove'
Expand Down Expand Up @@ -115,6 +120,12 @@ export function useDayEventHandlers(
const onMouseLeave: MouseEventHandler = (e) => {
dayPicker.onDayMouseLeave?.(date, activeModifiers, e);
};
const onPointerEnter: PointerEventHandler = (e) => {
dayPicker.onDayPointerEnter?.(date, activeModifiers, e);
};
const onPointerLeave: PointerEventHandler = (e) => {
dayPicker.onDayPointerLeave?.(date, activeModifiers, e);
};
const onTouchCancel: TouchEventHandler = (e) => {
dayPicker.onDayTouchCancel?.(date, activeModifiers, e);
};
Expand Down Expand Up @@ -186,6 +197,8 @@ export function useDayEventHandlers(
onKeyUp,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
onTouchCancel,
onTouchEnd,
onTouchMove,
Expand Down
3 changes: 3 additions & 0 deletions packages/react-day-picker/src/types/DayPickerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DayFocusEventHandler,
DayKeyboardEventHandler,
DayMouseEventHandler,
DayPointerEventHandler,
DayTouchEventHandler,
MonthChangeEventHandler,
WeekNumberClickEventHandler
Expand Down Expand Up @@ -251,6 +252,8 @@ export interface DayPickerBase {
onDayKeyDown?: DayKeyboardEventHandler;
onDayKeyUp?: DayKeyboardEventHandler;
onDayKeyPress?: DayKeyboardEventHandler;
onDayPointerEnter?: DayPointerEventHandler;
onDayPointerLeave?: DayPointerEventHandler;
onDayTouchCancel?: DayTouchEventHandler;
onDayTouchEnd?: DayTouchEventHandler;
onDayTouchMove?: DayTouchEventHandler;
Expand Down
7 changes: 7 additions & 0 deletions packages/react-day-picker/src/types/EventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export type DayMouseEventHandler = (
e: React.MouseEvent
) => void;

/** The event handler when a day gets a pointer event. */
export type DayPointerEventHandler = (
day: Date,
activeModifiers: ActiveModifiers,
e: React.PointerEvent
) => void;

/** The event handler when a month is changed in the calendar. */
export type MonthChangeEventHandler = (month: Date) => void;

Expand Down