react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Date titles

Open PMLP-novo opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. I want to communicate to my users why a day is highlighted or not highlighted

Describe the solution you'd like I would love to be able to give a dateTitle function that can generate a title for each day where it is relevant. Such that the users easily can hover and see extra info.

() => {
  const [startDate, setStartDate] = useState(new Date());
  const highlightDates=[subDays(new Date(), 7), addDays(new Date(), 7)] 
  return (
    <DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      highlightDates={highlightDates}
      dateTitle={(date)=>highlightDates.includes(date)?"Business logic"// Write some business logic telling the users why the specify day is highlighted
:null}
    />
  );
};

PMLP-novo avatar May 17 '22 06:05 PMLP-novo

@PMLP-novo Why can't this be solved using renderDayContents property ? Try following code.

() => {
  const [startDate, setStartDate] = useState(new Date());
  const highlightDates= [subDays(new Date(), 7), addDays(new Date(), 7)];
  const highlightedDays = highlightDates.map(d => d.getDate()); 
 
  const renderDayContents = (day, date) => {
    const tooltipText = "Business logic";
    if (highlightedDays.includes(day)) {
        return <span title={tooltipText}>{getDate(date)}</span>;
    } else {
       return <span>{getDate(date)}</span>;
    }
    
  };
  return (
    <DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      highlightDates={highlightDates}
      renderDayContents={renderDayContents}
    />
  );
};

shreekeshmurkar avatar Jun 12 '22 16:06 shreekeshmurkar

is getDate inbuild function?, if not can you show me how its done also

jees47 avatar Mar 31 '23 10:03 jees47