8

Fullcalendar React component:

import FullCalendar from "@fullcalendar/react";
import timeGrid from "@fullcalendar/resource-timegrid";
import resourceDayGridPlugin from '@fullcalendar/resource-daygrid';

class FC extends React.Component {
  calendarComponentRef = React.createRef();

  constructor(props) {
    super(props);    
    this.state = {
        events:[{ "id": 1, "title": "event 1", "description":"some description"},......]
    }  
  }

  eventRender(info){
    var tooltip = new Tooltip(info.el, {
      title: info.event.extendedProps.description,
      placement: 'top',
      trigger: 'hover',
      container: 'body'
    });
  }

  render() {
    return <FullCalendar                  
          events={this.state.getEvents}          
          defaultView="resourceTimeGridDay"
      plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
          eventRender={this.eventRender}
          schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
        />

  }
}

Tooltip.js included in header

<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<script rc="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js">/script>

Exactly trying to this demo in react, but it is not working in react version.

But tooltip not working

Fullcalendar react example project sample project react fullcalendar

ADyson
  • 57,178
  • 14
  • 51
  • 63
ramamoorthy_villi
  • 1,939
  • 1
  • 17
  • 40
  • Have you bound your function with your component yet? – Frank AK Jul 25 '19 at 04:21
  • 1
    Can you provide a JSfiddle link for me to have a look into this? – Ankur Mittal Jul 25 '19 at 04:34
  • @FrankAK yes done – ramamoorthy_villi Jul 25 '19 at 05:02
  • Can you make a minimal, reproducible example please, ideally using CodePen or JSFiddle or something. It's impossible to tell what is wrong from the tiny amount of out-of-context code posted here. See https://stackoverflow.com/help/minimal-reproducible-example for guidance on what to include – ADyson Jul 25 '19 at 06:33
  • first thing to verify is, is the `eventRender()` function definitely being executed? You can add a log command, or use the debugger to find out. Then we can narrow it down to issues with the tooltip directly – ADyson Jul 25 '19 at 08:49
  • Secondly, you haven't shown it above, but did you add the necessary CSS for the tooltips? There seems to be no file available for it, but if you look in the CodePen which is linked to from the [fullcalendar tooltip demo](https://fullcalendar.io/docs/event-tooltip-demo) you'll see there is some CSS written in there which is required for the tooltips to be visible. – ADyson Jul 25 '19 at 08:50
  • @ADyson 1) I can see the info details inside eventRender 2) Css included for Fullcalendar. there is no css for tooltip – ramamoorthy_villi Jul 25 '19 at 23:19
  • Well you need CSS for the tooltip, otherwise it will not show up. Like I said, you can get relevant CSS from the CodePen demo (see link in my last comment - from there, click to view in CodePen, and then look in the CSS part of the CodePen) – ADyson Jul 25 '19 at 23:32
  • @ADyson You are correct. I missed the CSS. Thanks – ramamoorthy_villi Jul 26 '19 at 03:41
  • @ADyson, yes, i includes css and js files, but it's not working on my side. instead of that, i got warning in console. CalendarDataManager.ts:669 Unknown option 'eventRender' – dev-assassin Jul 31 '20 at 12:25
  • @ninjadev1030 if you have a specific problem in your own code, you'll need to ask a new question about it. We cannot be sure what is wrong exactly unless we see more details. Please refer to this question with a link, if you have been trying one of the solutions from it or something. – ADyson Aug 01 '20 at 07:31

4 Answers4

11

FullCalendar v5

With content injection hook e.g. for Material-ui tooltip:

eventContent: ( arg ) => {
    return (
        <Tooltip title={ <Typography color="inherit">Tooltip with HTML</Typography> } arrow>
            { renderInnerContent( arg ) }
        </Tooltip>
    );
}

If you want to have the exact same content as the default, then copy the function from fullcalendar source:

/**
 * https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/common/src/common/StandardEvent.tsx#L79
 */
function renderInnerContent( innerProps ) {
    return (
        <div className='fc-event-main-frame'>
            { innerProps.timeText &&
            <div className='fc-event-time'>{ innerProps.timeText }</div>
            }
            <div className='fc-event-title-container'>
                <div className='fc-event-title fc-sticky'>
                    { innerProps.event.title || <Fragment>&nbsp;</Fragment> }
                </div>
            </div>
        </div>
    );
}

To differentiate ListView content from default content you can use this code (given a Calendar reference calendarRef):

eventContent: ( arg ) => {
    const data = calendarRef.current.getApi().getCurrentData();
    const viewSpec = data.viewSpecs[arg.view.type];
    let innerContent;
    if (viewSpec.component === ListView) {
        /**
         * https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/list/src/ListViewEventRow.tsx#L55
         */
        innerContent = renderListInnerContent( arg );
    } else {
        innerContent = renderInnerContent( arg );
    }
    return ( <Tooltip ... >{ innerContent }</Tooltip>);
};
User Rebo
  • 3,056
  • 25
  • 30
  • Interesting, thanks for this addition. Is there any way to import this from the lib so it's not copied and pasted? – Fernando Rojo Dec 07 '20 at 23:33
  • Unfotunately haven't made any progress in that direction. Lib does not export these components or provide access to the default one: https://github.com/fullcalendar/fullcalendar/issues/5927 – User Rebo Dec 11 '20 at 01:45
  • If your package updates with new CSS for those "fc" classes, but the HTML remains the same, it may cause some issues later down the line. – Logan Cundiff Feb 09 '22 at 17:18
3

Tooltip using Tooltip.js

eventRender(info){
    var tooltip = new Tooltip(info.el, {
      title: info.event.extendedProps.description,
      placement: 'top',
      trigger: 'hover',
      container: 'body'
    });
  }

In component :

render() {
    return <FullCalendar                  
          events={this.state.getEvents}          
          defaultView="resourceTimeGridDay"
      plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
          eventRender={this.eventRender}
          schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
        />

  }

OR

using react-tooltip

import ReactTooltip from 'react-tooltip'

and method to handle eventPosition

handleEventPositioned(info) {
  info.el.setAttribute("data-tip","some text tip");
   ReactTooltip.rebuild();
 }

and  

render() {
        return <FullCalendar                  
              events={this.state.getEvents}          
              defaultView="resourceTimeGridDay"
          plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
              eventPositioned={this.handleEventPositioned}
              schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
            />

      }
ramamoorthy_villi
  • 1,939
  • 1
  • 17
  • 40
  • it's not working on my side. when I tried to implement you, it's still not working. – dev-assassin Jul 30 '20 at 22:32
  • `react-tooltip` not working for me (using fullcalendar v5) – Jay Patel Sep 08 '20 at 05:57
  • 1
    Where's the tooltip.js coming from? I too am trying to implement the tooltip functionality inside my Calendar and I'm using React. – ShridharK May 05 '21 at 12:13
  • Please mention which React Fullcalendar version you are using for handleEventPositioned(info) { info.el.setAttribute("data-tip","some text tip"); ReactTooltip.rebuild(); } – spacedev Jan 02 '23 at 18:21
3

Tooltip using tippy with eventMouseEnter

    handleMouseEnter = (arg) =>{
    tippy(arg.el, {
        content: "my tooltip!"
    });
}

in component

render() {
    return (
            <FullCalendar ref={this.calendarRef}
                          plugins={[dayGridPlugin, interactionPlugin]}
                          initialView="dayGridMonth"
                          weekends={true}
                          eventMouseEnter={this.handleMouseEnter}

            />
    )
}
  • While I don't think an answer requiring a 3rd party package should be THE answer, this is the best answer in terms of simplicity and lack of potential bugs that will come from using the currently picked answer (requiring keeping track of source code) – Logan Cundiff Feb 09 '22 at 17:15
1

Best I did so far. This will at least give a title to an event.

<FullCalendar eventDidMount={renderEventContent} .....

function renderEventContent(info) {
  info.el.setAttribute('title', info.event.title)
}
despotbg
  • 740
  • 6
  • 12