Giter Club home page Giter Club logo

material-ui-datetimepicker's Introduction

Deprecated

We suggest migrate to material-ui v1 and use material-ui-pickers for date/time pickers. This project will not be longer supported.

Material UI Date & Time picker

Wrapper for Material UI Time and Date picker component

Component, that joins Material UI`s pickers into the one component, one input and 2 dialogs, appearing one by one.

We are recommending to use your custom wrapper outside of this component to store your custom props, and not pass Dialogs each time you use this package, because it should be solved in one of next material-ui versions

Dependencies

  • Material UI (Don`t use this package without material-ui, please)
  • React

Getting Started

Here is a quick example to get you started, it's all you need:

npm install material-ui-datetimepicker

Simple usage

import React from 'react';
import DateTimePicker from 'material-ui-datetimepicker';
import DatePickerDialog from 'material-ui/DatePicker/DatePickerDialog'
import TimePickerDialog from 'material-ui/TimePicker/TimePickerDialog';

class Demo extends React.Component {
  state = {
    dateTime: null
  }

  setDate = (dateTime) => this.setState({ dateTime })

  render() {
    return (
      <DateTimePicker 
        onChange={this.setDate}
        DatePicker={DatePickerDialog}
        TimePicker={TimePickerDialog}
      />
    );
  }
}

Advanced

Note that each of this props applied by default

import DatePickerDialog from 'material-ui/DatePicker/DatePickerDialog';
import TimePickerDialog from 'material-ui/TimePicker/TimePickerDialog';

<DateTimePicker
  value={new Date()} // picker value moment/string/number/js Date
  format='MMM DD, YYYY hh:mm A'
  timePickerDelay={150}
  returnMomentDate={false} // if true will return moment object
  className='datetime-container'
  textFieldClassName='datetime-input'
  name='picker' // form value name
  datePickerMode='portrait' // or landscape
  openToYearSelection={false} 
  disableYearSelection={false}
  hideCalendarDate={false}
  firstDayOfWeek={1}
  minutesStep={1}
  showCurrentDateByDefault={false}
  clearIcon={<ClearIcon />} // set null to not render nothing
  // available callbacks
  onChange={() => {}}
  onTimePickerShow={() => {}}
  onDatePickerShow={() => {}}
  onDateSelected={() => {}}
  onTimeSelected={() => {}}
  shouldDisableDate={() => {}}
  DatePicker={DatePickerDialog}
  TimePicker={TimePickerDialog}
  // styles
  clearIconStyle={{ }}
  textFieldStyle={{ }}
  style={{ }} // root
  timePickerBodyStyle={{ }}
/>

Customizing input

You can apply any of material ui Text Field props to the root.

<DateTimePicker
  floatingLabelFixed	
  floatingLabelText="Get my date"
  floatingLabelFocusStyle={{ marginTop: '10px' }}
  disabled={false}
  errorText='Required'
  id="some-id"
  fullWidth={false}
/>

Contributing

For information about how to contribute, see the CONTRIBUTING file.

LICENSE

The project is licensed under the terms of MIT license

material-ui-datetimepicker's People

Contributors

ankeetmaini avatar callmiy avatar dmtrkovalenko avatar golya avatar vitorsm 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

material-ui-datetimepicker's Issues

Textfield Full width problem

Hello:
When I tried to set textfield as fullwidth, I found the icon of closing would display at wrong location (It would fell-off to the second row. I suggested to add some containers to package the datetimepicker and closing icon. For example:
<div className="col-xs-10"><datetimePicker /></div><div className="col-xs-2><Icon /></div>"
How do you think?

Error type of props

Hello:
I had found there was type error in DatePicker and TimePicker. When building the demo codes, console would show warning said: "Failed prop type: Invalid prop TimePicker of type function supplied to DateTimePicker, expected object.". Same message with DatePicker. I tried to modify the source code to propTypes.func.isRequired then the warning was gone. Please help for checking if this issue is existed or not. Thanks.
By the way, this project was an awesome job. It saved me a lot of time. Thanks for contribution of authors.

Поправьте package.json

Сейчас import не резолвит пакет, т.к. в поле main указан несуществующий путь

Getting quirky display issue when clearing value from the field

I'm getting a weird problem when clearing the value from a field. See below. The value overlays on top of the floating text. Very weird.

image

Here's how I'm using it:

<DateTimePicker DatePicker={DatePickerDialog} TimePicker={TimePickerDialog} name="pickupWindowStart"
                                  floatingLabelText="Pickup Window Start" fullWidth={true} floatingLabelFixed={true}
                                  value={this.timeToDate(this.state.order.pickupWindowStart)}
                                  onChange={(e,v) => this.setOrderField('pickupWindowStart', this.dateToTime(v || e))} />

In this example I am passing in a Java Date() object or an empty string (I've also tried "null" and "undefined" when it is cleared) when it is empty.

clearIcon works even after disabled the field

Hi mate, first thing to mention this expansion really helps me.

I want to know that after disabled the field is there any way to avoid the clearIcon button because when I give the disabled property to the field it will only disable the date or time field but clearIcon remains accessible.
I also set the clearIcon property to null but it only hides the clearIcon not removes it from there we can still clear the field after clicking the right corner of it.

Thanks.

Disable focus on click

Hi, first it is an amazing expansion of Material UI!

But I have a question. When I am on a mobile device and want to select the date time picker, my keyboard jumps up, which is unnecessary, since you select the date by clicking on it. Is there a way to tell the component, not to focus on the input field on click, to prevent the keyboard jumping up?

Thanks, Balázs

How to update defaultTime?

Hi there,
thanks for this very nice component!

I ran into a weird problem I can't figure out on my own:

I'm trying to update the defaultTime after DateTimePicker is mounted but changing the assigned state value is not re-rendering the component properly:

          <DateTimePicker
            defaultTime={this.state.dateTime}

When e.g. running this in a click handler the input field of DateTimerPicker is not updated:

this.setState({dateTime: moment().add(30, "minutes")})

Is there a way to update the dateTime from the parent component or is this currently not supported?

Thanks!

error on importing.

import DateTimePicker from 'material-ui-datetimepicker';
I'm getting this error after just importing it.
error

Setting initialDate still broken

While I'm able to control the initial state of the TextField, when I activate the DateTimePicker, the picker that's displayed, still always defaults to Date.now().

It appears this was similar to the issue here for TimePicker: #15

You can see the behavior here: https://codesandbox.io/s/rrrvp0ljkn
If you click the first picker area, the DatePicker displayed gives you the correct date. But if you click on the DateTimePicker element, you get the current date.

AFAICT, the problem lies in the fact that the interface to DateTimePicker only allows for setting the value prop. While DatePicker has a value prop that can control the date for it, the DatePickerDialog does NOT have the value prop, but instead uses the initialDate prop, to then set the underlying value prop on it's DatePicker: https://github.com/mui-org/material-ui/blob/master/src/DatePicker/DatePickerDialog.js#L22

Warning in React 16

After updating to React 16, I get the following warning:

proxyConsole.js:54 Warning: React does not recognize the `timePickerDelay` prop on a DOM 
element. If you intentionally want it to appear in the DOM as a custom attribute, spell
it as lowercase `timepickerdelay` instead. If you accidentally passed it from a parent
component, remove it from the DOM element.
    in input (created by n)
    in div (created by n)
    in n (created by t)
    in span (created by t)
    in t (at NewBooking.jsx:408)
    in div (created by StepContent)
    in div (created by ExpandTransitionChild)
    in div (created by ExpandTransitionChild)
    in ExpandTransitionChild
    in div
    in TransitionGroup (created by ExpandTransition)
    in ExpandTransition (created by ExpandTransition)
    in ExpandTransition (created by StepContent)
    in div (created by StepContent)
    in StepContent (at NewBooking.jsx:405)
    in div (created by Step)
    in Step (at NewBooking.jsx:403)
    in div (created by Stepper)
    in Stepper (at NewBooking.jsx:336)
    in div (at NewBooking.jsx:335)
    in VerticalLinearStepper (at NewBooking.jsx:229)
    in div (created by DialogInline)
    in div (created by Paper)
    in Paper (created by DialogInline)
    in div (created by TransitionItem)
    in TransitionItem
    in div
    in TransitionGroup (created by DialogInline)
    in div (created by DialogInline)
    in DialogInline

Changing the locale?

Hi!
I just began experimenting with this component. It seems changing the locale of DatePickerDialog does not seem easy. Am I missing something here? Is there any way to accomplish this without adding new features? If not, should not it be a new feature?
Neo

How can select only year

I need to select only year, not need a day, month and time.
So is there way to select only year

clearIcon still seems to render the functionality of the button

Current setting on my doc:
clearIcon={null}
Documentation:
clearIcon={} // set null to not render nothing

I can still click on the button even though it is invisible. This is not a big deal for us, but I wanted to let you know. The package is working great otherwise, thank you for creating it.

Additional Issue related: In an effort to "catch" a user trying to delete a date/time by clicking on the invisible delete icon, I have found the following to be true..

If you add some logic to your onChange that essentially does not set the state of the date object of its' value is null (aka user has clicked on the delete button) your state will be preserved. However, the datetimepicker does not render this value. Instead it wipes what the user sees (because the clicked delete) You can check in memory that the value still exists because you stopped them from changing it, but the user will still believe the deleted it. I would suggest removing whatever logic is in place to wipe the "entry field" and instead always show the value that it is fed. OR change the clearIcon functionality to actually not allow them to delete the date object when it is set to null.

I hope this makes sense.

defaultTime error

Hello:
When I tried to set default time to datetime picker, I found timepicker would always the current time instead of the time I set. I tried to modify source codes as:
<TimePicker **initialTime**=... />
Then it worked. Please checked if it was right. Thanks.

onChange doesn't fire

Hello guys,

Hope you're doing well.
Thanks for this nice component!

I just download this library and started to use but i realized a problem with the onChange method.
My method setDatetime is not called :(

<DateTimePicker DatePicker={DatePickerDialog} TimePicker={TimePickerDialog} onChange={this.setDatetime} />

setDatetime = (datetime) => { console.log(datetime); }

Any errors in the console..
What happened?

i looked the material-ui-datepicker code and i saw you tried to fire up the onChange method inside SelectTime function but you the prop "onAccept" on material-ui timepicker but this props doesnt exist right?
Please let me know if am doing something wrong!
Thaaaaaaank you!!

Request for the ability to turn off time

This would allow it to be more flexible, for some reason some of the other react date time pickers are acting horrible, yours works, but I only need it for dates :)

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.