Props

PropTypeDefault
positionString"right"
disabledBooleanfalse
sortString
eachDaysInRangeBooleanfalse
onClickDateFunction
removeButtonBooleantrue
headerString
markFocusedBooleanfalse
focusedClassNameString
formatFunctionFunction

Sort

  • date
  • color

Important Note About onClickDate

The important thing about the onClickDate property is that if a date is clicked, the value of that date will be sent as an argument in onClickDate, but if the delete button is clicked, onClickDate will still be called but with an undefined argument.

Sort By Date

import DatePicker, { DateObject } from "react-multi-date-picker"
import DatePanel from "react-multi-date-picker/plugins/date_panel" 
.
.
.
const [value, setValue] = useState([
  new DateObject(),
  new DateObject().add(2, "days"),
  new DateObject().add(10, "days")
])
.
.
.
<DatePicker
  value={value}
  onChange={setValue}
  multiple
  plugins={[
    <DatePanel sort="date" />
  ]}
/>

Position Left

import DatePicker, { DateObject } from "react-multi-date-picker"
import DatePanel from "react-multi-date-picker/plugins/date_panel" 
.
.
.
const [value, setValue] = useState(
  [
    5, 
    10,
    15,
    20,
    25,
    30
  ].map(day => new DateObject().setDay(day))
)
.
.
.
<DatePicker
  value={value}
  onChange={setValue}
  multiple
  plugins={[
    <DatePanel position="left" />
  ]}
/>

Without Remove Button

import DatePicker, { DateObject } from "react-multi-date-picker"
import DatePanel from "react-multi-date-picker/plugins/date_panel" 
.
.
.
const [value, setValue] = useState([
  new DateObject(), 
  new DateObject().add(1, "day")
])
.
.
.
<DatePicker
  value={value}
  onChange={setValue}
  plugins={[
    <DatePanel
      removeButton={false}
    />
  ]}
/>

Date Click Listener

import DatePicker, { DateObject } from "react-multi-date-picker"
import DatePanel from "react-multi-date-picker/plugins/date_panel" 
.
.
.
const [value, setValue] = useState([
  new DateObject(), 
  new DateObject().add(1, "day")
])
.
.
.
<DatePicker
  value={value}
  onChange={setValue}
  plugins={[
    <DatePanel
      removeButton={false}
      onClickDate={dateObject => {
        let mustDelete = window.confirm("are you sure you want to delete this date ?")
      
        if (mustDelete) setValue(
          value.filter(date => date !== dateObject)
        )
      }}
    />
  ]}
/>

Custom Header Name

import DatePicker from "react-multi-date-picker"
import DatePanel from "react-multi-date-picker/plugins/date_panel" 
.
.
.
<DatePicker
  plugins={[
    <DatePanel header="All Dates" />
  ]}
/>

Customizing Focused Date

Clicking on any date in the DatePanel will focus on that date.

You can use the markFocused prop to better determine which date is focused. Also, you can set a className for the focused date to further customize it.

import DatePicker from "react-multi-date-picker"
import DatePanel from "react-multi-date-picker/plugins/date_panel"
.
.
.
const [focusedDate, setFocusedDate] = useState();
.
.
.
<DatePicker
  multiple
  sort
  onFocusedDateChange={setFocusedDate}
  onClose={() => setFocusedDate(undefined)}
  plugins={[
    <DatePanel markFocused focusedClassName="bg-red" />
  ]}
  mapDays={({ date, isSameDate }) => {
    let props = {}
    
    if (!isSameDate(date, focusedDate)) return

    props.style = { backgroundColor: "red" }
    
    return props
  }}
/>