-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DatePicker] How do you get the name/event of the control? Should we handle "event"? #6538
Comments
I ended up wrapping the Material UI component and I'm going to move forward. Works kind of nice based on what I need. Here's the code snippet. import React, { PropTypes } from 'react';
import BaseDatePicker from 'material-ui/DatePicker';
class DatePicker extends React.Component {
constructor() {
super();
this.state = {};
this.onChange = this.onChange.bind(this);
this.convertToMillis = this.convertToMillis.bind(this);
this.convertToDateString = this.convertToDateString.bind(this);
}
convertToMillis(dateString) {
return dateString.valueOf();
}
// Note that the default value for a MaterialUI DatePicker is {}
// NOT an empty string or any other value type
convertToDateString(dateMillis) {
if (dateMillis !== null && typeof yourVariable === 'object') {
return dateMillis;
}
return new Date(dateMillis);
}
// Note that event is always null, but it is the first arg.
// The reason it is null and it exists is because MUI wanted to maintain consistency
// with the Textfield control.
// http://www.material-ui.com/#/components/date-picker
onChange(event, date) { //eslint-disable-line no-unused-vars
const { onDataChange, name } = this.props;
const value = this.convertToMillis(date);
onDataChange(name, value);
}
render() {
const {
name,
valueMillis,
fullWidth,
style,
textFieldStyle
} = this.props;
const value = this.convertToDateString(valueMillis);
return (
<BaseDatePicker
onChange={this.onChange}
name={name} // This is required as Material-UI needs a key index on TextField
value={value}
fullWidth={fullWidth}
style={style}
textFieldStyle={textFieldStyle}/>
);
}
}
DatePicker.propTypes = {
name: PropTypes.string.isRequired,
onDataChange: PropTypes.func.isRequired,
valueMillis: PropTypes.any.isRequired,
fullWidth: PropTypes.bool,
style: PropTypes.object,
textFieldStyle: PropTypes.object
};
export default DatePicker; But I would be interested to see what you guys are thinking long term for DatePicker because I'd love to help more. |
@oshalygin DatePicker needs a rewrite as part of the migration to the new styling system on the How much help were you thinking? 😜 |
Yeah I'd love to help as much as I can. I don't think it would be too bad based on what I did to wrap the current DatePicker but I totally get that it will need to leverage the new styling effort. I'll start tracking the next branch and digging deeper over the next week :) |
@oshalygin Fantastic! There's a lot going on inside those components, so it's more than just updating to jss (although that's a big part of it). We're working towards:
@oliviertassinari will be a good person to discuss possible approaches with. We have this placeholder issue (#4787). |
@oshalygin Yeah, the DatePicker, and TimePicker definitely need to be reworked! You can find all the relevant issues using the tag filter. We need someone to take the ownership of the migration 😄
|
Awesome thank you gents, @oliviertassinari @mbrookes . Going to get crackin! Closing this issue out and will track with the filter. |
@oshalygin I am still facing the same issue. Using v0.20.0. |
just a heads-up, still facing this issue. |
Problem description
I looked through the docs and it looks like we're missing the
event
property that is null, which is used to properly set the values of the controlled component(such asTextField
).For instance to do the following:
property = event.target.name;
is not possible with a DatePicker because the event is null.The
date
property is properly hydrated but it makes things a bit wonky not being able to access the event itself, specifically the name of the component.Maybe we just need to add a name property?
What do you guys think?
EDIT: Looks like the biggest issue is when you want two DatePicker controls within the same root component.
Link to minimal working code that reproduces the issue
Versions
The text was updated successfully, but these errors were encountered: