Add Event on Hover

Hover-based interactions can be simple yet elegant. Using the cell-hover-in and cell-hover-out 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 calendarDayContent 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

<script setup>
import {
  formatDate,
  MbscEventcalendar,
  MbscToast,
  setOptions 
} from '@mobiscroll/vue'
import { ref } from 'vue'

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

const myEvents = ref([
  {
    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 hoveredDate = ref(null)
const isToastOpen = ref(false)
const toastMessage = ref('')

const myView = {
  calendar: {
    labels: 2
  }
}

function addEvent() {
  const newEvent = {
    start: hoveredDate.value,
    title: 'New Event'
  }
  myEvents.value = [...myEvents.value, newEvent]
  toastMessage.value = 'Event added on ' + formatDate('YYYY-MM-DD', hoveredDate.value)
  isToastOpen.value = true
}

// Mobiscroll resource hover events
function handleCellHoverIn(args) {
  hoveredDate.value = args.date
}

function handleCellHoverOut() {
  hoveredDate.value = null
}

function handleToastClose() {
  isToastOpen.value = false
}

function isHovered(date) {
  return hoveredDate.value && hoveredDate.value.getTime() === date.getTime()
}
</script>

<template>
  <MbscEventcalendar
    cssClass="mds-cell-summary"
    :view="myView"
    :data="myEvents"
    @cell-hover-in="handleCellHoverIn"
    @cell-hover-out="handleCellHoverOut"
  >
    <template #calendarDayContent="args">
      <button @click="addEvent" class="mds-cell-summary-btn" v-if="isHovered(args.date)">
        Add event
      </button>
    </template>
  </MbscEventcalendar>
  <MbscToast :isOpen="isToastOpen" :message="toastMessage" @close="handleToastClose" />
</template>

<style>
.mds-cell-summary .mbsc-calendar-cell {
  min-height: 145px;
}
.mds-cell-summary-btn {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  z-index: 3;
  font-size: 10px;
  padding: 8px;
  background: transparent;
  border-radius: 4px;
  border: 1px solid #5584b5;
  color: #5584b5;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.1s ease-out;
}
.mds-cell-summary-btn:hover {
  background: #5584b5;
  color: white;
  box-shadow: 0 2px 8px rgba(85, 132, 181, 0.3);
}
.mds-cell-summary-btn:active {
  box-shadow: 0 1px 4px rgba(85, 132, 181, 0.3);
}
</style>

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.