Hacker0x01 / react-datepicker

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

Datepicker style not working, any dependencies I need? #879

Closed johhansantana closed 7 years ago

johhansantana commented 7 years ago

When I click it does this instead:

screen shot 2017-06-09 at 11 10 50 am

is there a way to add the css manually?

when I check the dev tools there is no css being load up

screen shot 2017-06-09 at 3 43 55 pm
johhansantana commented 7 years ago

well I was having trouble importing react-datepicker/dist/react-datepicker.css' I'm not a webpack savvy so I just added it as a static file and now it works.

sislam6 commented 6 years ago

Just use a tilde in front of the the path. Just like you import bootstrap from the node dependencies.
Add this in your scss file import @import "~react-datepicker/dist/react-datepicker.css". This should work.

arun-topagi commented 5 years ago

@johhansantana if you solved this issue please let me know how, I tried, importing using require, importing using ~, made static css file in same directory tried to import but nothing worked for me.

AliAlperSakar commented 5 years ago

You should import css of react-datepicker=> import "react-datepicker/dist/react-datepicker.css" in index.js/index.ts file which includes getElementById('root').

DomantasP commented 5 years ago

Adding 'import 'react-datepicker/dist/react-datepicker-cssmodules.min.css' to my index.jsx solved the problem for me.

Boucherie commented 5 years ago

We tried adding both

import "react-datepicker/dist/react-datepicker.css" import 'react-datepicker/dist/react-datepicker-cssmodules.min.css'

and neither threw an error, but no styles. changing the file to something like

'react-datepicker/dist/react-datepicker-cssmodules.min.css1' throws an error, so they are being found and imported, but the chrome inspetor shows no styles :(

Nadya1993 commented 5 years ago

We tried adding both

import "react-datepicker/dist/react-datepicker.css" import 'react-datepicker/dist/react-datepicker-cssmodules.min.css'

and neither threw an error, but no styles. changing the file to something like

'react-datepicker/dist/react-datepicker-cssmodules.min.css1' throws an error, so they are being found and imported, but the chrome inspetor shows no styles :(

@Boucherie you can just import css from cdnjs: @import url('https://cdnjs.cloudflare.com/ajax/libs/react-datepicker/2.8.0/react-datepicker.min.css');

It was the only way that worked for me

larsblumberg commented 5 years ago

This is how the component looks to me:

Screenshot 2019-08-16 at 15 16 23

The mentioned imports are accepted (no compile error) but styling is not properly applied.

SidOfc commented 4 years ago

Before anything else, thank you for providing this component 💟

I think quite some folks end up here after checking this page: https://reactdatepicker.com/ which actually lacks a critical import line for the stylesheet. This import is included in the GH README.md, however:

image

Perhaps it would be a good idea to update the website to include this import there as well?

Cheers and keep up the good work 👍

topovik commented 4 years ago

import DatePicker from "react-datepicker" require('react-datepicker/dist/react-datepicker.css') it should work

SidOfc commented 4 years ago

While it should work, that doesn't mean it is obvious that you'd do so from the actual website. It's not too bad since GH docs mention it but just adding the import line I think will prevent folks from having to search for it or figure out by themselves that it's "not on the website, but only on GH".

Also, if you can import DatePicker, can't you use ES6 modules to import 'react-datepicker/dist/react-datepicker.css' in your setup @ffpetrovic? :)

ffpetrovic commented 4 years ago

Yes, if you can import the component using ES6 import then it should work for .css files as well. And this section should be added to the website. Since the npm install part is there, the following steps necessary for the library to work/look properly should be listed as well.

michael-harley commented 4 years ago

This is how the component looks to me:

Screenshot 2019-08-16 at 15 16 23

The mentioned imports are accepted (no compile error) but styling is not properly applied.

image

This is how it looked to me as well, and the styling is not properly applied. Anyone know how to fix this styling? I thought it should looked like this: https://reactdatepicker.com/

clinton-slice commented 4 years ago

Add the line below to the top of your file where you are using the DatePicker import 'react-datepicker/dist/react-datepicker.css';

franlol commented 4 years ago

In my case, under a nextjs project with babel7 and webpack4, the only way that I can fix the css is

import DatePicker from "react-datepicker"
import "react-datepicker/src/stylesheets/datepicker.scss";

Hope it can help someone

Eezi commented 4 years ago

In my case the import of the css file didn't work at all, but I fixed it by replacing line in the css file: content: "\00d7"; with this --> content: ×

import "react-datepicker/dist/react-datepicker.css";

michelmany commented 3 years ago

@franlol your solution worked for me. Thanks!

ThusharaSampath commented 3 years ago

import "react-datepicker/dist/react-datepicker.css in index.js

Try this one ! works for me ! thanks AliAlperSakar

nielsuit227 commented 3 years ago

This becomes especially annoying on a dev-server. I had to copy the CSS and manually move it.

nevingrowingstars commented 3 years ago

In my case, under a nextjs project with babel7 and webpack4, the only way that I can fix the css is

import DatePicker from "react-datepicker"
import "react-datepicker/src/stylesheets/datepicker.scss";

Hope it can help someone

This is the one fix which is working....

ndnenkov commented 3 years ago

I was having an issue with webpacker where it worked in dev, but not in other environments. I had to add

@import 'react-datepicker/dist/react-datepicker';

To application.scss rather the inline import.

kbiswas100 commented 3 years ago

if nothing works then you can add this class to your css file ,


.react-datepicker__time-list-item {
    width: 70px;
    margin-left: -40px;
    padding-left: 18px !important;
}
GodAlmighty990 commented 2 years ago

I had to add import 'react-datepicker/dist/react-datepicker.css'; to my App.js.

Here is my App.js file

This could also be your index.js file

import React from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; import Layout from './layouts/Layout'; import 'react-toastify/dist/ReactToastify.min.css'; import 'react-datepicker/dist/react-datepicker.css'; import 'react-image-lightbox/style.css';

const App = () => {

return (

  <Router basename={process.env.PUBLIC_URL}>

    <Layout />

  </Router>

); };

export default App;

pedro-pinho commented 2 years ago

In my case it was because I had the postcss-purgecss plugin installed, and it was purging some of the css To fix it, I had to update my postcss.config.js file to this:

module.exports = {
  plugins: [
    'postcss-flexbugs-fixes',
    [
      'postcss-preset-env',
      {
        autoprefixer: {
          flexbox: 'no-2009',
        },
        stage: 3,
        features: {
          'custom-properties': false,
        },
      },
    ],
    [
      '@fullhuman/postcss-purgecss',
      {
        content: ['./pages/**/*.{js,jsx,ts,tsx}', './components/**/*.{js,jsx,ts,tsx}', './styles/*.{scss}'],
        defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
        safelist: ['html', 'body', 'react-datepicker'],
      },
    ],
  ],
}
DevOzair commented 1 year ago

I ended up copying everything in the react-datepicker.css into my main index CSS, and added it in a section below. Nothing above was working.

(new to all this, 3rd day at React so my solution is 100% not the best :D )

themegabyte commented 1 year ago

FYI for "next": "12.3.1"

Add your import to the _app.js file:

Like so:

import "../styles/globals.css";
import "react-datepicker/dist/react-datepicker.css"; # 👈

import { SWRConfig } from "swr";
import axios from "axios";
...

Documentation here: https://nextjs.org/docs/basic-features/built-in-css-support#import-styles-from-node_modules

ashwindevx commented 1 year ago

I ended up copying everything in the react-datepicker.css into my main index CSS, and added it in a section below. Nothing above was working.

(new to all this, 3rd day at React so my solution is 100% not the best :D )

Can you share the style you copied and pasted to your index CSS file? Thanks!

amanattryb commented 5 months ago

I am stack with this issue as I am trying to run yarn run build

Error: 'Calendar' is not exported by node_modules/react-date-range/dist/index.js, imported by src/composite-component/date-picker/date-picker.tsx

martijnrusschen commented 5 months ago

@amanattryb Based on the error it seems you may be using a different component.