React-datepicker: Initial style error?

Created on 12 Jan 2016  Â·  10Comments  Â·  Source: Hacker0x01/react-datepicker

Hello.

I've recently discovered this cool tool and wanted to use it but when i init the tool in my application i looks like this:

skaermbillede 2016-01-12 kl 11 00 53

Its missing all styles that you guys have. Im currently firing up the tool like this:

<DatePicker selected={this.state.startDate}/>

and i've importede React, Moment and DatePicker from my node modules like this:
import DatePicker from 'react-datepicker'; import moment from 'moment'; import React from 'react';

Is there any explanation why this is happning ?

Most helpful comment

I'm having a similar problem and adding import 'react-datepicker/dist/react-datepicker.css'; to my component JSX (ES6) doesn't work. I'm using gulp to build my CSS. Any suggestion on what am I missing? I can verify the datepicker* styles are not on the built CSS.
The gulp task is this:
(notice I tried to add the full path of the datepicker.css and still didn't work)

gulp.task('build-sass', function () {
    return gulp
        .src(
            ['src/styles/**/*.scss',
            'node_modules/react-datepicker/dist/react-datepicker.css']
        )
        .pipe(sass().on('error', sass.logError))
        .on('error', notify.onError(function (err) {
              console.error(err.codeFrame ? err.codeFrame : err.message);
              return 'CSS build failed.';
        }))
        .pipe(concat('site.css'))
        .pipe(gulp.dest('site/compiled-css/'))
        .pipe(notify('✓ CSS build success.'));
});

All 10 comments

NB: When i look my inspect tools, the classes are applyed on the html document but not loaded in?

@Nopzen Try to embed the datepicker's CSS file manually in your HTML document

@aspirisen - Its added through npm, i guess that datepicker should use the stylesheet it self?

  • its not possible for me to add the css file from the node_modules folder.

What code tool are you using? Can you add import 'react-datepicker/dist/react-datepicker.css'; as the docs suggest to bring in the stylesheet (if it's webpack/browserify based)?

@rafeememon's suggestion should work in this case.

@rafeememon - Works :+1: Thanks!

Maybe this should be added to the main doc here? I stumbled on the same issue.

@ir-fuel, it's in the "Installation" example in the readme =)

_doh_

I'm having a similar problem and adding import 'react-datepicker/dist/react-datepicker.css'; to my component JSX (ES6) doesn't work. I'm using gulp to build my CSS. Any suggestion on what am I missing? I can verify the datepicker* styles are not on the built CSS.
The gulp task is this:
(notice I tried to add the full path of the datepicker.css and still didn't work)

gulp.task('build-sass', function () {
    return gulp
        .src(
            ['src/styles/**/*.scss',
            'node_modules/react-datepicker/dist/react-datepicker.css']
        )
        .pipe(sass().on('error', sass.logError))
        .on('error', notify.onError(function (err) {
              console.error(err.codeFrame ? err.codeFrame : err.message);
              return 'CSS build failed.';
        }))
        .pipe(concat('site.css'))
        .pipe(gulp.dest('site/compiled-css/'))
        .pipe(notify('✓ CSS build success.'));
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcabrerazuniga picture jcabrerazuniga  Â·  3Comments

formigone picture formigone  Â·  3Comments

pinturic picture pinturic  Â·  3Comments

ro-savage picture ro-savage  Â·  3Comments

sarav1234 picture sarav1234  Â·  3Comments