Add Event on Hover

Hover-based interactions can be simple yet elegant. Using the onCellHoverIn and onCellHoverOut events, the calendar dynamically displays an "Add event" button when users hover over day cells, providing an intuitive way to create new events with minimal interface clutter.

For customizing the cell content appearance, the renderCalendarDayContent is the perfect candidate, as it holds the basic structure of the day cell.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Show an "Add event" button on day cell hover in a event calendar — reveal event creation without cluttering the calendar interface.

Code

import { Eventcalendar, formatDate, setOptions, Toast  } from '@mobiscroll/react';
import { useCallback, useMemo, useState } from 'react';

setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

function App() {
  const [hoveredDate, setHoveredDate] = useState(null);
  const [isToastOpen, setToastOpen] = useState(false);
  const [toastMessage, setToastMessage] = useState('');
  const [myEvents, setEvents] = useState(
    () => [
      {
        start: '2026-10-02T12:00',
        end: '2026-10-02T16:00',
        title: 'Company Strategy Offsite',
        color: '#90bcff',
      },
      {
        start: '2026-10-07T09:00',
        end: '2026-10-07T17:00',
        title: 'R&D Innovation Workshop',
        color: '#ffdfaf',
      },
      {
        start: '2026-10-15T10:00',
        end: '2026-10-15T15:00',
        title: 'Client Feedback Review',
        color: '#ffb9ad',
      },
      {
        start: '2026-10-19T09:00',
        end: '2026-10-19T19:00',
        title: 'Team Building Adventure',
        color: '#f3c1ff',
      },
      {
        start: '2026-10-23T11:00',
        end: '2026-10-23T15:00',
        title: 'Sales Summit & Training',
        color: '#b5eff8',
      },
      {
        start: '2026-10-25T10:00',
        end: '2026-10-25T15:00',
        title: 'Executive Planning Retreat',
        color: '#c7ffbb',
      },
      {
        start: '2026-10-29T14:00',
        end: '2026-10-29T17:00',
        title: 'Marketing Team Conference',
        color: '#ffeeb6',
      },
    ],
    [],
  );

  const myView = useMemo(
    () => ({
      calendar: {
        labels: 2,
      },
    }),
    [],
  );

  const addEvent = useCallback(() => {
    const newEvent = {
      start: hoveredDate,
      title: 'New Event',
    };

    setEvents((myEvents) => [...myEvents, newEvent]);
    setToastMessage('Event added on ' + formatDate('YYYY-MM-DD', hoveredDate));
    setToastOpen(true);
  }, [hoveredDate]);

  const customDayContent = useCallback(
    (args) => {
      const isHovered = hoveredDate && hoveredDate.getTime() === args.date.getTime();

      return (
        isHovered && (
          <button onClick={addEvent} className="mds-cell-summary-btn">
            Add event
          </button>
        )
      );
    },
    [hoveredDate, addEvent],
  );

  const handleCellHoverIn = useCallback((args) => {
    setHoveredDate(args.date);
  }, []);

  const handleCellHoverOut = useCallback(() => {
    setHoveredDate(null);
  }, []);

  const handleToastClose = useCallback(() => {
    setToastOpen(false);
  }, []);

  return (
    <>
      <Eventcalendar
        data={myEvents}
        view={myView}
        className="mds-cell-summary"
        renderCalendarDayContent={customDayContent}
        onCellHoverIn={handleCellHoverIn}
        onCellHoverOut={handleCellHoverOut}
      />
      <Toast isOpen={isToastOpen} message={toastMessage} onClose={handleToastClose} />
    </>
  );
}

export default App;

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.