Giter Site home page Giter Site logo

wojtekmaj / react-datetime-picker Goto Github PK

View Code? Open in Web Editor NEW
526.0 7.0 70.0 7.76 MB

A datetime picker for your React app.

Home Page: https://projects.wojtekmaj.pl/react-datetime-picker

License: MIT License

HTML 0.22% CSS 3.03% TypeScript 96.76%
react calendar date date-picker time time-picker datetime datetime-picker

react-datetime-picker's Introduction

npm downloads CI

React-DateTime-Picker

A datetime picker for your React app.

  • Supports virtually any language
  • No moment.js needed

tl;dr

  • Install by executing npm install react-datetime-picker or yarn add react-datetime-picker.
  • Import by adding import DateTimePicker from 'react-datetime-picker'.
  • Use by adding <DateTimePicker />. Use onChange prop for getting new values.

Demo

A minimal demo page can be found in sample directory.

Online demo is also available!

Consider native alternative

If you don't need to support legacy browsers and don't need the advanced features this package provides, consider using native datetime input instead. It's more accessible, adds no extra weight to your bundle, and works better on mobile devices.

<input aria-label="Date and time" type="datetime-local" />

Looking for just a date picker or a time picker?

React-DateTime-Picker will play nicely with React-Date-Picker and React-Time-Picker. Check them out!

Getting started

Compatibility

Your project needs to use React 16.3 or later. If you use an older version of React, please refer to the table below to find a suitable React-DateTime-Picker version.

React version Newest compatible React-DateTime-Picker version
≥16.3 latest
≥16.0 2.x

React-Calendar, on which React-DateTime-Picker relies heavily, uses modern web technologies. That's why it's so fast, lightweight and easy to style. This, however, comes at a cost of supporting only modern browsers.

Legacy browsers

If you need to support legacy browsers like Internet Explorer 10, you will need to use Intl.js or another Intl polyfill along with React-DateTime-Picker.

Installation

Add React-DateTime-Picker to your project by executing npm install react-datetime-picker or yarn add react-datetime-picker.

Usage

Here's an example of basic usage:

import { useState } from 'react';
import DateTimePicker from 'react-datetime-picker';

type ValuePiece = Date | null;

type Value = ValuePiece | [ValuePiece, ValuePiece];

function MyApp() {
  const [value, onChange] = useState<Value>(new Date());

  return (
    <div>
      <DateTimePicker onChange={onChange} value={value} />
    </div>
  );
}

Custom styling

If you want to use default React-DateTime-Picker, React-Calendar and React-Clock styling to build upon it, you can import them by using:

import 'react-datetime-picker/dist/DateTimePicker.css';
import 'react-calendar/dist/Calendar.css';
import 'react-clock/dist/Clock.css';

User guide

DateTimePicker

Displays an input field complete with custom inputs, native input, a calendar, and a clock.

Props

Prop name Description Default value Example values
amPmAriaLabel aria-label for the AM/PM select input. n/a "Select AM/PM"
autoFocus Automatically focuses the input on mount. n/a true
calendarAriaLabel aria-label for the calendar button. n/a "Toggle calendar"
calendarClassName Class name(s) that will be added along with "react-calendar" to the main React-Calendar <div> element. n/a
  • String: "class1 class2"
  • Array of strings: ["class1", "class2 class3"]
calendarIcon Content of the calendar button. Setting the value explicitly to null will hide the icon. (default icon)
  • String: "Calendar"
  • React element: <CalendarIcon />
  • React function: CalendarIcon
className Class name(s) that will be added along with "react-datetime-picker" to the main React-DateTime-Picker <div> element. n/a
  • String: "class1 class2"
  • Array of strings: ["class1", "class2 class3"]
clearAriaLabel aria-label for the clear button. n/a "Clear value"
clearIcon Content of the clear button. Setting the value explicitly to null will hide the icon. (default icon)
  • String: "Clear"
  • React element: <ClearIcon />
  • React function: ClearIcon
clockClassName Class name(s) that will be added along with "react-clock" to the main React-Calendar <div> element. n/a
  • String: "class1 class2"
  • Array of strings: ["class1", "class2 class3"]
closeWidgets Whether to close the widgets on value selection. Note: It's recommended to use shouldCloseWidgets function instead. true false
data-testid data-testid attribute for the main React-DateTime-Picker <div> element. n/a "datetime-picker"
dayAriaLabel aria-label for the day input. n/a "Day"
dayPlaceholder placeholder for the day input. "--" "dd"
disableCalendar When set to true, will remove the calendar and the button toggling its visibility. false true
disableClock When set to true, will remove the clock. false true
disabled Whether the datetime picker should be disabled. false true
format Input format based on Unicode Technical Standard #35. Supported values are: y, M, MM, MMM, MMMM, d, dd, H, HH, h, hh, m, mm, s, ss, a. Note: When using SSR, setting this prop may help resolving hydration errors caused by locale mismatch between server and client. n/a "y-MM-dd h:mm:ss a"
hourAriaLabel aria-label for the hour input. n/a "Hour"
hourPlaceholder placeholder for the hour input. "--" "hh"
id id attribute for the main React-DateTime-Picker <div> element. n/a "datetime-picker"
isCalendarOpen Whether the calendar should be opened. false true
isClockOpen Whether the clock should be opened. false true
locale Locale that should be used by the datetime picker and the calendar. Can be any IETF language tag. Note: When using SSR, setting this prop may help resolving hydration errors caused by locale mismatch between server and client. Server locale/User's browser settings "hu-HU"
maxDate Maximum date that the user can select. Periods partially overlapped by maxDate will also be selectable, although React-DateTime-Picker will ensure that no later date is selected. n/a Date: new Date()
maxDetail The most detailed calendar view that the user shall see. View defined here also becomes the one on which clicking an item in the calendar will select a date and pass it to onChange. Can be "hour", "minute" or "second". Don't need hour picking? Try React-Date-Picker! "minute" "second"
minDate Minimum date that the user can select. Periods partially overlapped by minDate will also be selectable, although React-DateTime-Picker will ensure that no earlier date is selected. n/a Date: new Date()
minuteAriaLabel aria-label for the minute input. n/a "Minute"
minutePlaceholder placeholder for the minute input. "--" "mm"
monthAriaLabel aria-label for the month input. n/a "Month"
monthPlaceholder placeholder for the month input. "--" "mm"
name Input name. "datetime" "myCustomName"
nativeInputAriaLabel aria-label for the native datetime input. n/a "Date"
onCalendarClose Function called when the calendar closes. n/a () => alert('Calendar closed')
onCalendarOpen Function called when the calendar opens. n/a () => alert('Calendar opened')
onChange Function called when the user picks a valid datetime. If any of the fields were excluded using custom format, new Date(y, 0, 1, 0, 0, 0), where y is the current year, is going to serve as a "base". n/a (value) => alert('New date is: ', value)
onClockClose Function called when the clock closes. n/a () => alert('Clock closed')
onClockOpen Function called when the clock opens. n/a () => alert('Clock opened')
onFocus Function called when the user focuses an input. n/a (event) => alert('Focused input: ', event.target.name)
onInvalidChange Function called when the user picks an invalid datetime. n/a () => alert('Invalid datetime')
openWidgetsOnFocus Whether to open the widgets on input focus. Note: It's recommended to use shouldOpenWidgets function instead. true false
portalContainer Element to render the widgets in using portal. n/a document.getElementById('my-div')
returnValue Which dates shall be passed by the calendar to the onChange function and onClick{Period} functions. Can be "start", "end" or "range". The latter will cause an array with start and end values to be passed. "start" "range"
required Whether datetime input should be required. false true
secondAriaLabel aria-label for the second input. n/a "Second"
secondPlaceholder placeholder for the second input. "--" "ss"
shouldCloseWidgets Function called before the widgets close. reason can be "buttonClick", "escape", "outsideAction", or "select". widget can be "calendar" or "clock". If it returns false, the widget will not close. n/a ({ reason, widget }) => reason !== 'outsideAction' && widget === 'calendar'
shouldOpenWidgets Function called before the widgets open. reason can be "buttonClick" or "focus". widget can be "calendar" or "clock". If it returns false, the widget will not open. n/a ({ reason, widget }) => reason !== 'focus' && widget === 'calendar'
showLeadingZeros Whether leading zeros should be rendered in datetime inputs. false true
value Input value. Note that if you pass an array of values, only first value will be fully utilized. n/a
  • Date: new Date(2017, 0, 1, 22, 15)
  • String: "2017-01-01T22:15:00"
  • An array of dates: [new Date(2017, 0, 1, 22, 15), new Date(2017, 0, 1, 23, 45)]
  • An array of strings: ["2017-01-01T22:15:00", "2017-01-01T23:45:00"]
yearAriaLabel aria-label for the year input. n/a "Year"
yearPlaceholder aria-label for the year input. "----" "yyyy"

Calendar

DateTimePicker component passes all props to React-Calendar, with the exception of className (you can use calendarClassName for that instead). There are tons of customizations you can do! For more information, see Calendar component props.

Clock

DateTimePicker component passes all props to React-Clock, with the exception of className (you can use clockClassName for that instead). There are tons of customizations you can do! For more information, see Clock component props.

License

The MIT License.

Author

Wojciech Maj Wojciech Maj

react-datetime-picker's People

Contributors

dependabot[bot] avatar geraldbcastillo avatar vlad2689 avatar wojtekmaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-datetime-picker's Issues

Cannot integrate this picker into my project

my package.json is like below
"react": "^15.6.1",
"react-datetime-picker": "1.0.1",
"react-dom": "^15.6.1"

Here is my code snippet

render() {
        let dateTime = new Date();
        return (
            <div>
                <div className="pure-g">
                    <div className="pure-u-1">
                        <Paper className="config-paper" zDepth={2}>
                            <div className="config-paper">
                                <DateTimePicker value={dateTime}/>
                            </div>
                        </Paper>
                    </div>
                </div>
            </div>
        )
    }

The page cannot be rendered properly, and in console i found some error messages

proxyConsole.js:56
Warning: Failed prop type: The prop className is marked as required in MonthInput, but its value is undefined.
in MonthInput (created by DateTimeInput)
in DateTimeInput (created by DateTimePicker)
in div (created by DateTimePicker)
in div (created by DateTimePicker)
in DateTimePicker (at multi-logs.js:31)
in div (at multi-logs.js:30)
in div (created by Paper)
in Paper (at multi-logs.js:29)
in div (at multi-logs.js:28)
in div (at multi-logs.js:27)
in div (at multi-logs.js:26)
in MultiLogs (created by Route)
in Route (created by withRouter(MultiLogs))
in withRouter(MultiLogs) (created by Connect(withRouter(MultiLogs)))
in Connect(withRouter(MultiLogs)) (created by Route)
in Route (at App.js:86)
in div (at App.js:80)
in div (at App.js:76)
in div (at App.js:75)
in div (at App.js:71)
in div (at App.js:60)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:59)
in MuiThemeProvider (at App.js:58)
in App (created by Connect(App))
in Connect(App) (at index.js:17)
in div (at index.js:16)
in Provider (at index.js:15)
stack_frame_overlay_proxy_console @ proxyConsole.js:56
printWarning @ warning.js:33
warning @ warning.js:57
checkReactTypeSpec @ checkReactTypeSpec.js:78
validatePropTypes @ ReactElementValidator.js:160
createElement @ ReactElementValidator.js:214
renderMonth @ DateTimeInput.js:252
(anonymous) @ DateTimeInput.js:325
renderCustomDateInputs @ DateTimeInput.js:320
render @ DateTimeInput.js:399
(anonymous) @ ReactCompositeComponent.js:793
measureLifeCyclePerf @ ReactCompositeComponent.js:73
_renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:792
_renderValidatedComponent @ ReactCompositeComponent.js:819
performInitialMount @ ReactCompositeComponent.js:359
mountComponent @ ReactCompositeComponent.js:255
mountComponent @ ReactReconciler.js:43
mountComponentIntoNode @ ReactMount.js:102
perform @ Transaction.js:141
batchedMountComponentIntoNode @ ReactMount.js:124
perform @ Transaction.js:141
batchedUpdates @ ReactDefaultBatchingStrategy.js:60
batchedUpdates @ ReactUpdates.js:95
_renderNewRootComponent @ ReactMount.js:317
_renderSubtreeIntoContainer @ ReactMount.js:399
render @ ReactMount.js:420
./src/index.js @ index.js:15
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
fn @ bootstrap 410fcd7b7fbcfbcece90:87
0 @ registerServiceWorker.js:108
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
proxyConsole.js:56 Warning: Failed prop type: The prop className is marked as required in DayInput, but its value is undefined.
in DayInput (created by DateTimeInput)
in DateTimeInput (created by DateTimePicker)
in div (created by DateTimePicker)
in div (created by DateTimePicker)
in DateTimePicker (at multi-logs.js:31)
in div (at multi-logs.js:30)
in div (created by Paper)
in Paper (at multi-logs.js:29)
in div (at multi-logs.js:28)
in div (at multi-logs.js:27)
in div (at multi-logs.js:26)
in MultiLogs (created by Route)
in Route (created by withRouter(MultiLogs))
in withRouter(MultiLogs) (created by Connect(withRouter(MultiLogs)))
in Connect(withRouter(MultiLogs)) (created by Route)
in Route (at App.js:86)
in div (at App.js:80)
in div (at App.js:76)
in div (at App.js:75)
in div (at App.js:71)
in div (at App.js:60)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:59)
in MuiThemeProvider (at App.js:58)
in App (created by Connect(App))
in Connect(App) (at index.js:17)
in div (at index.js:16)
in Provider (at index.js:15)
stack_frame_overlay_proxy_console @ proxyConsole.js:56
printWarning @ warning.js:33
warning @ warning.js:57
checkReactTypeSpec @ checkReactTypeSpec.js:78
validatePropTypes @ ReactElementValidator.js:160
createElement @ ReactElementValidator.js:214
renderDay @ DateTimeInput.js:241
(anonymous) @ DateTimeInput.js:323
renderCustomDateInputs @ DateTimeInput.js:320
render @ DateTimeInput.js:399
(anonymous) @ ReactCompositeComponent.js:793
measureLifeCyclePerf @ ReactCompositeComponent.js:73
_renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:792
_renderValidatedComponent @ ReactCompositeComponent.js:819
performInitialMount @ ReactCompositeComponent.js:359
mountComponent @ ReactCompositeComponent.js:255
mountComponent @ ReactReconciler.js:43
mountComponentIntoNode @ ReactMount.js:102
perform @ Transaction.js:141
batchedMountComponentIntoNode @ ReactMount.js:124
perform @ Transaction.js:141
batchedUpdates @ ReactDefaultBatchingStrategy.js:60
batchedUpdates @ ReactUpdates.js:95
_renderNewRootComponent @ ReactMount.js:317
_renderSubtreeIntoContainer @ ReactMount.js:399
render @ ReactMount.js:420
./src/index.js @ index.js:15
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
fn @ bootstrap 410fcd7b7fbcfbcece90:87
0 @ registerServiceWorker.js:108
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
proxyConsole.js:56 Warning: Failed prop type: The prop className is marked as required in YearInput, but its value is undefined.
in YearInput (created by DateTimeInput)
in DateTimeInput (created by DateTimePicker)
in div (created by DateTimePicker)
in div (created by DateTimePicker)
in DateTimePicker (at multi-logs.js:31)
in div (at multi-logs.js:30)
in div (created by Paper)
in Paper (at multi-logs.js:29)
in div (at multi-logs.js:28)
in div (at multi-logs.js:27)
in div (at multi-logs.js:26)
in MultiLogs (created by Route)
in Route (created by withRouter(MultiLogs))
in withRouter(MultiLogs) (created by Connect(withRouter(MultiLogs)))
in Connect(withRouter(MultiLogs)) (created by Route)
in Route (at App.js:86)
in div (at App.js:80)
in div (at App.js:76)
in div (at App.js:75)
in div (at App.js:71)
in div (at App.js:60)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:59)
in MuiThemeProvider (at App.js:58)
in App (created by Connect(App))
in Connect(App) (at index.js:17)
in div (at index.js:16)
in Provider (at index.js:15)
stack_frame_overlay_proxy_console @ proxyConsole.js:56
printWarning @ warning.js:33
warning @ warning.js:57
checkReactTypeSpec @ checkReactTypeSpec.js:78
validatePropTypes @ ReactElementValidator.js:160
createElement @ ReactElementValidator.js:214
renderYear @ DateTimeInput.js:262
(anonymous) @ DateTimeInput.js:327
renderCustomDateInputs @ DateTimeInput.js:320
render @ DateTimeInput.js:399
(anonymous) @ ReactCompositeComponent.js:793
measureLifeCyclePerf @ ReactCompositeComponent.js:73
_renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:792
_renderValidatedComponent @ ReactCompositeComponent.js:819
performInitialMount @ ReactCompositeComponent.js:368
mountComponent @ ReactCompositeComponent.js:255
mountComponent @ ReactReconciler.js:43
mountComponentIntoNode @ ReactMount.js:102
perform @ Transaction.js:141
batchedMountComponentIntoNode @ ReactMount.js:124
perform @ Transaction.js:141
batchedUpdates @ ReactDefaultBatchingStrategy.js:60
batchedUpdates @ ReactUpdates.js:95
_renderNewRootComponent @ ReactMount.js:317
_renderSubtreeIntoContainer @ ReactMount.js:399
render @ ReactMount.js:420
./src/index.js @ index.js:15
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
fn @ bootstrap 410fcd7b7fbcfbcece90:87
0 @ registerServiceWorker.js:108
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
proxyConsole.js:56 Warning: Failed prop type: The prop className is marked as required in HourInput, but its value is undefined.
in HourInput (created by DateTimeInput)
in DateTimeInput (created by DateTimePicker)
in div (created by DateTimePicker)
in div (created by DateTimePicker)
in DateTimePicker (at multi-logs.js:31)
in div (at multi-logs.js:30)
in div (created by Paper)
in Paper (at multi-logs.js:29)
in div (at multi-logs.js:28)
in div (at multi-logs.js:27)
in div (at multi-logs.js:26)
in MultiLogs (created by Route)
in Route (created by withRouter(MultiLogs))
in withRouter(MultiLogs) (created by Connect(withRouter(MultiLogs)))
in Connect(withRouter(MultiLogs)) (created by Route)
in Route (at App.js:86)
in div (at App.js:80)
in div (at App.js:76)
in div (at App.js:75)
in div (at App.js:71)
in div (at App.js:60)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:59)
in MuiThemeProvider (at App.js:58)
in App (created by Connect(App))
in Connect(App) (at index.js:17)
in div (at index.js:16)
in Provider (at index.js:15)
stack_frame_overlay_proxy_console @ proxyConsole.js:56
printWarning @ warning.js:33
warning @ warning.js:57
checkReactTypeSpec @ checkReactTypeSpec.js:78
validatePropTypes @ ReactElementValidator.js:160
createElement @ ReactElementValidator.js:214
renderHour @ DateTimeInput.js:271
(anonymous) @ DateTimeInput.js:357
renderCustomTimeInputs @ DateTimeInput.js:352
render @ DateTimeInput.js:401
(anonymous) @ ReactCompositeComponent.js:793
measureLifeCyclePerf @ ReactCompositeComponent.js:73
_renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:792
_renderValidatedComponent @ ReactCompositeComponent.js:819
performInitialMount @ ReactCompositeComponent.js:368
mountComponent @ ReactCompositeComponent.js:255
mountComponent @ ReactReconciler.js:43
mountComponentIntoNode @ ReactMount.js:102
perform @ Transaction.js:141
batchedMountComponentIntoNode @ ReactMount.js:124
perform @ Transaction.js:141
batchedUpdates @ ReactDefaultBatchingStrategy.js:60
batchedUpdates @ ReactUpdates.js:95
_renderNewRootComponent @ ReactMount.js:317
_renderSubtreeIntoContainer @ ReactMount.js:399
render @ ReactMount.js:420
./src/index.js @ index.js:15
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
fn @ bootstrap 410fcd7b7fbcfbcece90:87
0 @ registerServiceWorker.js:108
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
proxyConsole.js:56 Warning: Failed prop type: The prop className is marked as required in MinuteInput, but its value is undefined.
in MinuteInput (created by DateTimeInput)
in DateTimeInput (created by DateTimePicker)
in div (created by DateTimePicker)
in div (created by DateTimePicker)
in DateTimePicker (at multi-logs.js:31)
in div (at multi-logs.js:30)
in div (created by Paper)
in Paper (at multi-logs.js:29)
in div (at multi-logs.js:28)
in div (at multi-logs.js:27)
in div (at multi-logs.js:26)
in MultiLogs (created by Route)
in Route (created by withRouter(MultiLogs))
in withRouter(MultiLogs) (created by Connect(withRouter(MultiLogs)))
in Connect(withRouter(MultiLogs)) (created by Route)
in Route (at App.js:86)
in div (at App.js:80)
in div (at App.js:76)
in div (at App.js:75)
in div (at App.js:71)
in div (at App.js:60)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:59)
in MuiThemeProvider (at App.js:58)
in App (created by Connect(App))
in Connect(App) (at index.js:17)
in div (at index.js:16)
in Provider (at index.js:15)
stack_frame_overlay_proxy_console @ proxyConsole.js:56
printWarning @ warning.js:33
warning @ warning.js:57
checkReactTypeSpec @ checkReactTypeSpec.js:78
validatePropTypes @ ReactElementValidator.js:160
createElement @ ReactElementValidator.js:214
renderMinute @ DateTimeInput.js:287
(anonymous) @ DateTimeInput.js:359
renderCustomTimeInputs @ DateTimeInput.js:352
render @ DateTimeInput.js:401
(anonymous) @ ReactCompositeComponent.js:793
measureLifeCyclePerf @ ReactCompositeComponent.js:73
_renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:792
_renderValidatedComponent @ ReactCompositeComponent.js:819
performInitialMount @ ReactCompositeComponent.js:368
mountComponent @ ReactCompositeComponent.js:255
mountComponent @ ReactReconciler.js:43
mountComponentIntoNode @ ReactMount.js:102
perform @ Transaction.js:141
batchedMountComponentIntoNode @ ReactMount.js:124
perform @ Transaction.js:141
batchedUpdates @ ReactDefaultBatchingStrategy.js:60
batchedUpdates @ ReactUpdates.js:95
_renderNewRootComponent @ ReactMount.js:317
_renderSubtreeIntoContainer @ ReactMount.js:399
render @ ReactMount.js:420
./src/index.js @ index.js:15
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
fn @ bootstrap 410fcd7b7fbcfbcece90:87
0 @ registerServiceWorker.js:108
webpack_require @ bootstrap 410fcd7b7fbcfbcece90:669
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
(anonymous) @ bootstrap 410fcd7b7fbcfbcece90:715
invariant.js:42 Uncaught Error: MonthInput.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
at invariant (invariant.js:42)
at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:828)
at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:359)
at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:255)
at Object.mountComponent (ReactReconciler.js:43)
at ReactDOMComponent.mountChildren (ReactMultiChild.js:234)
at ReactDOMComponent._createInitialChildren (ReactDOMComponent.js:701)
at ReactDOMComponent.mountComponent (ReactDOMComponent.js:520)
at Object.mountComponent (ReactReconciler.js:43)
at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:368)
at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:255)
at Object.mountComponent (ReactReconciler.js:43)
at ReactDOMComponent.mountChildren (ReactMultiChild.js:234)
at ReactDOMComponent._createInitialChildren (ReactDOMComponent.js:701)
at ReactDOMComponent.mountComponent (ReactDOMComponent.js:520)
at Object.mountComponent (ReactReconciler.js:43)
at ReactDOMComponent.mountChildren (ReactMultiChild.js:234)
at ReactDOMComponent._createInitialChildren (ReactDOMComponent.js:701)
at ReactDOMComponent.mountComponent (ReactDOMComponent.js:520)
at Object.mountComponent (ReactReconciler.js:43)
at ReactCompositeComponentWrapper.performInitialMount (ReactCompositeComponent.js:368)
at ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:255)
at Object.mountComponent (ReactReconciler.js:43)
at ReactDOMComponent.mountChildren (ReactMultiChild.js:234)
at ReactDOMComponent._createInitialChildren (ReactDOMComponent.js:701)

Input are not properly sized in some scenarios

I am experience a problem when the component is loaded with a provided value. Only the first digit of day, month, year, as well as time, is displayed (see image).
screenshot 2018-10-29 at 17 34 58

The input fields are then correctly resized either by changing the value prop, or by clicking on one of the fields.

Calendar hides when the input field changes

When the input field changes (either by typing a different date or simply using the up/down arrows) the calendar is closed. I would expect it to stay open and update with the new date, what do you think?

The specified value "false" is not a valid number

I don't get this on your demo page, but I see it on my install, so it might be a conflict with something?
When I click the clear icon or I set the value to null programaticly, the following warning is triggered:

The specified value "false" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?

image

It does work, even with the warning, the input box is cleared and it can be used again. i've stripped mine down to mimic your example code:
`import React from 'react';
import DateTimePicker from 'react-datetime-picker';

export default class MyDatePicker extends React.Component {

constructor(props) {
	super(props);

	this.state = {
		date: new Date(),
	}
}

onChange = date => this.setState({ date })


render() {

	return(
		<DateTimePicker
			onChange={this.onChange}
			value={this.state.date}
		/>
	);
}

}
`

this is my package.json

"dependencies": {
"npm": "^6.3.0",
"react": "^16.4.2",
"react-burger-menu": "^2.5.2",
"react-date-picker": "^6.11.2",
"react-datetime-picker": "^1.4.1",
"react-dom": "^16.4.2",
"react-input-mask": "^2.0.2",
"react-loadable": "^5.4.0",
"react-notifications": "^1.4.3",
"react-overlays": "^0.8.3",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4",
"react-table": "^6.8.6",
"react-tippy": "^1.2.2",
"recharts": "^1.1.0",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0",
"socket.io-client": "^2.1.1"
},

Can't enter hour lower than 12


This happens when using an hour lower than 12. It doesn't let me input 24-hour times like 13, 14, etc, so I figure it's supposed to be 12-hour, yet 12-hour doesn't work properly.

Use with velocity-react

We're using velocity-react to slideIn the picker, but using this seems to cause an issue with the calculation of input sizes. For example, here's our usage:

        <VelocityTransitionGroup
          enter={{
            animation: 'slideDown',
            duration: 250
          }}
          leave={{
            animation: 'slideUp',
            duration: 250
          }}
        >
          {showDate ? (
            <Wrapper>
                <DateTimePicker
                  onChange={this.onDateChange}
                  date={date}
                />
            </Wrapper>
          ) : (
            undefined
          )}
        </VelocityTransitionGroup>

Without velocity, the input year for example shows correct (2019) however, when used with velocity it only shows 2 and I can see the value is applied correctly to the input, it's just not sizing correctly, until you then open the calendar again. I guess my question is any idea why this could effect the resizing or if there's a way to manually force it?

Calendar not closing when input is blurred using a keyboard

Preconditions:

  • 2 date-time pickers are given, one after another;
  • input focus is on the second date-time picker, calendar is open.

Use Shift+Tab to navigate to the first picker.

Expected result: calendar only for the first picker is displayed.
Actual result: calendars for both fields are displayed.

When use just Tab to navigate between pickers, only one calendar is displayed.

Video example: https://www.dropbox.com/s/hl87otpyq46z79z/Screen%20Recording%202018-11-16%20at%2015.01.11.mov?dl=0

in AM/PM mode I can select a datetime less than minDate

I am trying to have a date picker that only allows future datetimes.

It is now 6:10pm, I set the minDate to minDate={new Date()}.

If I set the date picker to today, select the hour input and press up to 12, my picked datetime is 12pm which is in the past.

It feels like the hour input should start at 12 and go upto 11 ie 12 1 2 3 4 5 6 7 8 9 10 11, so pushing up always goes to the future. Pretty sure that's not possible with a regular HTML5 number input with min max attributes, but am sure it could be done in React.

Date Time Picker does not work when date time values are deleted one by one from textbox's

I am using react-datetime-picker library using below example component definition:

<DateTimePicker onChange={this.updateDateTime} value={new Date()} disableClock={true}  />

When I delete the date time entries manually using keyboard then it breaks the React UI.

I am getting below error.

dates.js?ada8:586 Uncaught Error: Invalid date: Invalid Date
    at getISOLocalDate (dates.js?ada8:586)
    at eval (NativeInput.js?b89b:95)
    at NativeInput.render (NativeInput.js?b89b:79)
    at finishClassComponent (VM22996 react-dom.development.js:13193)
    at updateClassComponent (VM22996 react-dom.development.js:13155)
    at beginWork (VM22996 react-dom.development.js:13824)
    at performUnitOfWork (VM22996 react-dom.development.js:15863)
    at workLoop (VM22996 react-dom.development.js:15902)
    at HTMLUnknownElement.callCallback (VM22996 react-dom.development.js:100)
    at Object.invokeGuardedCallbackDev (VM22996 react-dom.development.js:138)
getISOLocalDate @ dates.js?ada8:586
(anonymous) @ NativeInput.js?b89b:95
render @ NativeInput.js?b89b:79
finishClassComponent @ react-dom.development.js?61bb:13193
updateClassComponent @ react-dom.development.js?61bb:13155
beginWork @ react-dom.development.js?61bb:13824
performUnitOfWork @ react-dom.development.js?61bb:15863
workLoop @ react-dom.development.js?61bb:15902
callCallback @ react-dom.development.js?61bb:100
invokeGuardedCallbackDev @ react-dom.development.js?61bb:138
invokeGuardedCallback @ react-dom.development.js?61bb:187
replayUnitOfWork @ react-dom.development.js?61bb:15310
renderRoot @ react-dom.development.js?61bb:15962
performWorkOnRoot @ react-dom.development.js?61bb:16560
performWork @ react-dom.development.js?61bb:16482
flushInteractiveUpdates$1 @ react-dom.development.js?61bb:16727
batchedUpdates @ react-dom.development.js?61bb:2143
dispatchEvent @ react-dom.development.js?61bb:4555
interactiveUpdates$1 @ react-dom.development.js?61bb:16714
interactiveUpdates @ react-dom.development.js?61bb:2150
dispatchInteractiveEvent @ react-dom.development.js?61bb:4532
warning.js?da67:33 Warning: Received NaN for the `value` attribute. If this is expected, cast the value to a string.
    in input (created by MonthInput)
    in MonthInput (created by DateTimeInput)
    in div (created by DateTimeInput)
    in DateTimeInput (created by DateTimePicker)
    in div (created by DateTimePicker)
    in div (created by DateTimePicker)

Two datetime pickers - transparency problem

Hi,

Having two datetime pickers in a column cause that the above datetime picker is behaving as transparent towards the below one.

Here are the pictures:
datetimepicker1
datetimepicker2

How to make the first calendar & clock not transparent ? (It has no transparency attributes!)

Add className variable for input wrapper

So, I just spent some time trying to get this looking nice in my project.

screenshot_20181112_174310

All I needed to do was be able to apply a class to the outer wrapper et voila:

screenshot_20181112_174240

Have you thought about adding this as an option? It seems like a no-brainer with regards to compatibility.

Module not found: Error: Can't resolve 'css' in '/Users/george/Desktop/coding challenge/syndicator'

Hi, I'm getting this error Module not found: Error: Can't resolve 'css' in '/Users/george/Desktop/coding challenge/syndicator'
Here is my webpack config:

var path = require("path");

module.exports = {
  context: __dirname,
  entry: "./frontend/syndicator.jsx",
  output: {
    path: path.resolve(__dirname, 'app', 'assets', 'javascripts'),
    filename: "bundle.js"
  },
  module: {
    rules: [
      {
        test: [/\.jsx?$/, /\.js?$/],
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['env', 'react']
        }
      },
      {
        test: /(\.css|\.sass|\.scss)$/,
        loaders: ['style', 'css?sourceMap', 'sass?sourceMap']
      }
    ]
  },
  devtool: 'source-map',
  resolve: {
    extensions: [".js", ".jsx", "*"]
  }
};

Any idea what i'm missing

Error after yarn add

Strange. After yarn add react-datetime-picker I've got error:

An unexpected error occurred: "EACCES: permission denied, unlink '/Users/tomek/Library/Caches/Yarn/npm-react-time-picker-2.4.0-66c66848713c0a385484da560334de2b5708ff58/.yarn-tarball.tgz'".

yarn-error.log

Input should select current value on focus

Hi there! This looks like a great project.
I noticed a behavior that looks odd to me.
If I click on one of the time components, let's say the month, and I start typing, instead of replacing the current content with the new value it add the new value to the value that is already there (making it not valid, of course).
In the following example, I clicked between the 2 and 018 in the year field, and typed "2019". I would expect it to just replace the year instead of producing this result (see date-time picker on macOS default calendar app). This is easily achieved by selecting the all text when the user clicks in any position. Maybe this behavior can also be toggled with some setting. I would be happy to contribute for this.
screen shot 2018-10-06 at 11 04 19

overlaying issue

Hi,
I have 2 react-datetime-picker stacked vertically and the 1st calendar is popping under the second one.
any clue ?
cheers

Clock staying open when the calendar opened by clicking the calendar icon.

Is this a feature request or a bug?
A bug

What's the issue?
When the clock is open and I click on the calendar icon, the clock doesn't go hidden so that the calendar can show. The calendar instead opens under the clock.

screen shot 2018-06-29 at 1 33 10 am

This behaviour remains so long as the user keeps clicking on the calendar icon to toggle the calendar on/off.

What's the expected behavior?
When the clock is open and I click the calendar icon, the clock widget should close so the calendar widget opens and takes up the space.

I can't think of a single use case where I'd want both widgets on the same date time picker at the same time.

How can we replicate this issue?

  1. Visit a page on your project with the DateTimePicker component rendered on the dom.
  2. Click on the time to show the clock widget.
  3. Click on the calendar icon by the right to show the calendar widget. The calendar shows but below the clock. The clock stays open.
  4. Click on the calendar icon again to hide the calendar widget. The calendar widget hides. Clock remains open.

Error: Failed to get hours from date: 2018-11-14T06:00:00.000Z

A date string format like "2018-11-14T06:00:00.000Z" is not being datified, even though this is the purest form of a date string as far as Javascript is concerned.

dates.js:25 Uncaught (in promise) Error: Failed to get hours from date: 2018-11-14T06:00:00.000Z.
    at getHours (dates.js:25)
    at getDerivedStateFromProps (DateTimeInput.js:646)
    at applyDerivedStateFromProps (react-dom.development.js:11265)
    at mountClassInstance (react-dom.development.js:11583)
    at updateClassComponent (react-dom.development.js:13145)
    at beginWork (react-dom.development.js:13824)
    at performUnitOfWork (react-dom.development.js:15863)
    at workLoop (react-dom.development.js:15902)
    at renderRoot (react-dom.development.js:15942)
    at performWorkOnRoot (react-dom.development.js:16560)

MonthInput.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.

Hey,

I'd like to use datetime-picker in my project but I always get this error.
MonthInput.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.

I'm working on react 15.4.2 so as you mentioned I used v.1.0.1.
I've seen similar issues and someone said the calendar should be installed. I did that (v.2.7.0) but also got the error.

Because you already encountered this issue, do you have updates about it?

Thanks,

-Thomas

Add default styles for today's date

Hi there,

I've just started using this and I notice that there is a class set on the calendar on the today's date tile (react-calendar__tile--now), but there are no styles applied to it which differentiate it from the others in any way.

Is this intentional? Would be nice to have the default styles include styling for that too. Maybe a very light grey, something subtle (when it is not the currently selected date).

Improvements: support for European format (dd/mm/yyyy rather than American mm/dd/yyyy)

Cześć Wojtek,
congratulations for this library. After customizing a bit the css I can say I am definitely very satisfied, it works well for my purposes.

I have however a request, I hope it is somehow achievable.
In the project I am working on, the result data, shown to the user after filtering by date, present the information about the date in the European format, while the date time picker presents it under the American format only. This brings a little bit of confusion for an user which is inserting the date manually, without opening the calendar popup (And this is my case, since there are a lot of filters to be filled very quickly in our application).

Is there a way to include a prop for specifying the format we want the date to be shown in the picker after the user's selection or after the user's insertion? That would be great and would save me from the users' lynching :)

Cheers

Unable to hide the clock

I'd like to be able to disable the clock, so it doesn't appear when editing the time.

However the isClockOpen prop doesn't seem to control this, as I thought it would; looking at the code, this doesn't appear to be a feature, unless I'm missing something?

If this is not currently a feature, nor in development (and is something you think would be a positive addition) please let me know - I'd be interested in trying to add this.

Collision with bottom --above-label css needs to be added

When the datetime picker collides with the bottom of the screen it adding the --above-label tag to the classname, however there is no css in the DateTimePicker.less file to support rendering the picker above the label.

Solution is to add the following to DateTimePicker.less:

&--above-label {
bottom: 100%;
top: auto;
}

AM/PM difference not used with `max/minDate`

There is an issue when using two pickers for a range (start, end).

I've setup my component to have a startDate and an endDate in my state.

state = {
   endDate: new Date(),
   startDate: new Date()
}

These are changed via the onChange method on their respective datetime-pickers.

In addition, the start picker has a maxDate value of state.endDate, and the end picker has a minDate value of state.startDate

Now the problem: if I set the start to be 01/01/2019 7:00 AM, I cannot set the end to be 01/01/2019 4:00 PM

I can, however, set endDate to be 01/01/2019 8:00 PM. It seems like it's comparing the hour only and checking the end hour (4) < start hour (7) without taking AM/PM into consideration.

Here is a setup of the situation:
https://codesandbox.io/embed/r44vx6jxr4

Compatibility with React 17

In React 17, lifecycle methods componentWillMount, componentWillUpdate and componentWillReceiveProps will be deprecated. These are to be replaced with getDerivedStateFromProps static method.

Possibility to use only input field

Can this component be used without the actual calendar picker (only the input field)?
I have my own calendar widget and I would like to use display it when the input field gets on focus, is it possible? I don't see onFocus/onBlur events.

Error: Invalid date

Hi,
I have problem with manual typing a year, which throws an error invalid date.
You can also simulate this error on page: http://projects.wojtekmaj.pl/react-datetime-picker/
Try to add 999 after year 2018. And when you will add 3rd "9" like this 201899 - error appears.

This is not a problem when you have passed validation and it is "red". So I think that this problem can be fixed with triggering validation after typing?

image

image

image

Display only date without time

I need to only display the date without time.
present date displayed like "10/20/2018 12:00 AM" but i need to display date like "10/20/2018".Please help me out of this issue

Better ux when manually entering numbers

It would be cool if the component handled some cases better when manually entering the digits.

  • When a value has been typed, focus should automatically move to the next field
  • When I enter a 0 in the month or date field, the value is set to 00 as expected, but when I then enter a different digit, it is just appended, like 003. 3-digit numbers shouldn't be possible there.

I think the date time control shown in Chrome for input type="datetime-local" is a great example to model this component's behavior on. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

Also notice how it automatically skips the month and year parts in the first example because the month and year of the maximum and minimum values have the same month and year.

I've looked over the code base to try and understand it to see if I could help and contribute to these improvements, but there's a lot to dig into. Still, I'll keep reading code :).

Setting locale to en-AU doesn't display option to select AM/PM

Setting locale to en-AU it is not displaying AM/PM in time selection. Here is my code.

<DateTimePicker onChange={this.updateStartDT} value={this.state.StartDT} locale="en-AU" use12Hours="false"/>

I am using chrome for testing. Also setting use12Hours="false" not displaying time in 24 hour format.

Styling looks off

Hey wojtekmaj,

Great work on the picker! It is great -- thanks!

Would you be able to share the configuration that let to the picker to look like it does in your demo?

If not, would you be able to let me know how to get rid of these underlines?
screen shot 2018-08-19 at 2 54 54 pm

Thanks!

Odd result when importing css

Hi, I tried importing the datetime picker directly (import DateTimePicker from 'react-datetime-picker';) but then it somehow overwrote all the styles from my other components (!).

To get around this I ended up using the nostyled version combined with copying the css files into my own repo and importing them through a scss preprocessor.

I'm not sure what caused this, but I thought I'd let you know.

This is using Webpack 3.10, here is how I configure the css part of it:

  {
    test: /\.css$/,
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: [cacheLoader, { loader: 'css-loader', options: { minifier: true } }],
    }),
  },

  {
    test: /\.scss$/,
    use: ExtractTextPlugin.extract({
      use: [
        cacheLoader,
        {
          loader: 'css-loader',
          options: {},
        },
        {
          loader: 'sass-loader',
          options: {
            includePaths: [
              path.resolve(rootPath, 'scss'),
              path.resolve(rootPath, 'node_modules/foundation-sites/scss'),
            ],
          },
        },
        {
          loader: 'sass-resources-loader',
          options: {
            // Provide path to the file with resources
            resources: path.resolve(rootPath, 'scss', 'ask-settings.scss'),
          },
        },
      ],
      fallback: 'style-loader',
    }),
  },

What happens is that when I include the .css files then only those files will be bundled up into the style.css file that is produced.

how to change the position of a calendar

let me give you brief info, while i try to change the year/month/date, calendar got popped up in upward direction, which got cut off on my screen, so i am not able to see full calendar, i want to change the position of my calendar in downward direction, could you please help me on that?

issue with react-datetime-picker initial set-up

///React_Dashboard/node_modules/react-calendar/dist/Calendar.css:1
(function (exports, require, module, __filename, __dirname) { .react-calendar {
^
SyntaxError: Unexpected token .
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Module._extensions..js (module.js:579:10)

Type definitions

Could you please consider creating type definitions for this library to make Typescript experience more pleasant?

Date Format

Hi,
I am a beginner and my question is how can I change the date format from MM/DD/YYYY to DD/MM/YYYY.

Thanks :)

AM/PM picker not displayed for some locales

The date time picker use locale to determine if the hour format is 12 or 24, but this is not always the best way. for example, if the locale is "zh-Hans-CN" it will use 12 hours format, but in China the 24 hours format is the primary time format.
further more, even use 12 hours format, the time result is also not correct for "zh-Hans-CN"
The Intl.DateTimeFormat with "zh-Hans-CN" locale will format the time "15:00:00" to "下午3:00:00" where (下午 is pm), but datetime picker finally dispaly the time as 3:00:00.
Is it possible we add an option such as "h24", and if it has value, just pass it to the formatDate function, and in this function, check if the parameter "h24" has value or not, and set "hour12" to true or false when call new Intl.DateTimeFormat

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.