Skip to Content
Version 2.0 is out with React 19 support and an ESM build. Read the migration guide →
Interactions & callbacks

Interactions & callbacks

The calendar reports clicks through callback props. Each one receives a value and the React mouse event. Click around below to see what each callback receives.

View
Loading calendar…

Callbacks at a glance

CallbackFires when you clickFirst argumentViews
onItemClickAn itemThe itemAll
onCellClickAn empty part of a cellDateInfoAll
onCellHeaderClickThe header strip of a day columnDateInfoWEEK_TIME, DAY, WEEK_IN_PLACE, DAY_IN_PLACE
onDayNumberClickA day number'yyyy-MM-dd' stringAll
onDayStringClickA weekday name'yyyy-MM-dd' string, or currentDate in day viewsAll
onHourClickAn hour labelHour number or DateInfo, see belowWEEK_TIME, DAY, DAY_REVERSE, WEEK_IN_PLACE, DAY_IN_PLACE
onColorDotClickA color dot or a legend entryThe color dotAll
setCurrentDatePrevious, next or “Today”'yyyy-MM-dd' stringAll

All callbacks are optional. Each one has the signature (value, event) => void.

onItemClick

<Calendar onItemClick={(item, event) => { openEditor(item.id); }} />

item contains all the fields you passed in data, plus a few the calendar adds while laying items out, such as isStart, length, startMinute and endMinute. Use your own fields, like id, and ignore the rest.

The click does not bubble to the cell underneath, so clicking an item never also fires onCellClick.

Items in the row above the timeline, which are longer than 24 hours, call onItemClick only when they use the default rendering. If you pass renderHeaderItem, handle clicks inside your own element.

onCellClick and onCellHeaderClick

Both receive a DateInfo for the clicked cell. A common use is creating an item where the user clicked:

<Calendar onCellClick={({ timeDate }) => { // 'yyyy-MM-dd' in MONTH and WEEK, 'yyyy-MM-dd HH:mm:ss' in hour-based views const start = new Date(timeDate.replace(' ', 'T')); createEvent(start); }} />

onCellHeaderClick fires for the strip at the top of a day column in the hour-based views. In MONTH and WEEK that area belongs to the cell, so onCellClick fires instead.

onHourClick

The hour labels on the left of the timeline are clickable. The first argument depends on the view:

  • WEEK_TIME and WEEK_IN_PLACE pass the hour as a number from 0 to 23.
  • DAY, DAY_REVERSE and DAY_IN_PLACE pass a DateInfo with hour set.
<Calendar onHourClick={(value) => { const hour = typeof value === 'number' ? value : value.hour; console.log('Clicked hour', hour); }} />

onDayNumberClick and onDayStringClick

Both receive the date of the clicked day. A typical pattern is to drill down from a month or week into that day:

const [view, setView] = useState('MONTH'); const [currentDate, setCurrentDate] = useState('2025-06-02'); <Calendar currentView={view} currentDate={currentDate} setCurrentDate={setCurrentDate} onDayNumberClick={(day) => { setCurrentDate(day); setView('DAY'); }} />;

In the day views the weekday name refers to the day already shown, so onDayStringClick passes currentDate back as you provided it.

The DateInfo object

interface DateInfo { date: string; // 'yyyy-MM-dd' day: number; // day of the month month: number; // 0-11 year: number; isCurrentDay: boolean; // true for today isCurrentMonth?: boolean; hour?: number; // 0-23 in hour-based views timeDate: string; // local key: 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss' timeDateUTC: string; // the same moment as an ISO string }

timeDate is the same key that cellDisplayMode uses, so you can store it directly in inactiveCells.

In MONTH and WEEK, timeDate is a plain date and timeDateUTC is midnight UTC of that date, not local midnight. Build local dates from timeDate instead.

currentDate decides which period is shown. The navigation steps by a month in MONTH, a week in the week views and a day in the day views.

  • Built-in navigation: pass setCurrentDate. The calendar shows previous, next and “Today” buttons and calls setCurrentDate with the new date as 'yyyy-MM-dd'.
  • Your own navigation: leave setCurrentDate out. The buttons disappear and you change currentDate from your own controls.
import { addMonths, format, subMonths } from 'date-fns'; function MyCalendar({ events }) { const [date, setDate] = useState(new Date()); return ( <> <div className="toolbar"> <button onClick={() => setDate((d) => subMonths(d, 1))}>Previous</button> <strong>{format(date, 'MMMM yyyy')}</strong> <button onClick={() => setDate((d) => addMonths(d, 1))}>Next</button> </div> <Calendar data={events} currentView="MONTH" currentDate={date} activeTimeDateField="startTime-endTime" /> </> ); }

currentDate accepts a 'yyyy-MM-dd' string or a Date, and defaults to today.

Last updated on