Skip to content

How to make Calendar icon show in React Date Picker? #4291

@AtGbemiga

Description

@AtGbemiga

Describe the bug
I'm using React Date Picker, which I installed via npm i react-datepicker. Everything works except the calendar icon which doesn't display. The docs says to add showIcon to the JSX element to display the calendar icon, this does not show the icon, it only makes the JSX element bigger.

To Reproduce

"use client";

import { useState } from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";


export default function Form() {
  const [dateRange, setDateRange] = useState<[Date | null, Date | null]>([
    null,
    null,
  ]);
  const [startDate, endDate] = dateRange;

  return (
    <form>
      <DatePicker
        showIcon
        selectsRange={true}
        startDate={startDate}
        endDate={endDate}
        onChange={(update) => {
          console.log("Selected Date Range:", update);
          setDateRange(update);
        }}
        minDate={new Date()}
        withPortal
      />
    </form>
  );
}

Expected behavior
A calendar icon should be displayed.

Screenshots
No icon

Desktop (please complete the following information):

  • OS: Windows
  • Browser chrome
  • Version "^4.16.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions