Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
8.06k stars 2.24k forks source link

Display of component is wonky #4895

Open scottyj503 opened 3 months ago

scottyj503 commented 3 months ago

Describe the bug I loaded a test site ( npm create vite@latest datepicker-test -- --template react-ts ) and installed react-datepicker. With the following code:

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

const Example = () => {
  const [startDate, setStartDate] = useState(new Date());
  return (
    <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
  );
};
function App() {
  return <Example />;
}

export default App;

I am seeing:

Screenshot 2024-06-12 at 3 29 01 PM

Here is my App.css:

#root {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
}

I am running OS X and the screenshot is from Chrome. I am seeing the same thing on Firefox.

I am expecting:

Screenshot 2024-06-12 at 3 39 09 PM

I presume I am doing something dumb here. 🙃

mateokurti commented 3 months ago

From the README.md:

You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).

So, adding this to you imports should resolve the issue:

import "react-datepicker/dist/react-datepicker.css";
kng0111 commented 3 months ago

Rewrite the code and refresh it