-
-
Notifications
You must be signed in to change notification settings - Fork 1.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] Use keyboard to write date #6232
Comments
I agree it is also a bit difficult to pick year if you are using this for entering something like a date of birth. Being able to type in text would help this. |
Can the DatePicker be used without the built in TextField? That would allow the user full control over the textbox and when/how to display the picker. |
@nathanmarks A user could created their own version of DatePicker without TextField using DatePickerDialog or Calendar. |
@mbrookes If that's the case, that sounds like the best option for specific use cases such as this. |
@nathanmarks is this a specific use case? Its a input field that the native implementation allows for keyboard input. IMHO, this is the normal use case for any input component on a browser. |
@isaackearl The UX is poor (per MD spec), but if you click on the year in the date-display you get a list of years to choose from. |
@mbrookes Ah yes I am aware you can do that, but I still think it is not intuitive or easy to select a date quickly. I am having user tests on an application I've created and every tester has noted that it is difficult to use the datepicker for selecting date of birth. It does look nice though. |
The spec recommends using segmented dropdowns when the UX is more appropriate |
@nathanmarks Yes - I said the same thing to @tintin1343 on the inline timepicker PR, as I think the current datepicker inline is not good UX, and we should deprecate it in favour of something built with dropdowns/ |
So your suggestion is to be able choose which type of input method user prefer? Basically add one property which would indicate it? |
@ddeath have you made any progress towards this? |
@rigelk Hi not at all, I am waiting for response from team member, I do not want to do something what will be thrown away... so I switched to select boxes as probably everybody here. |
@rigelk in the meanwhile I created a component in my project with something like this:
The user can either write in the TextField of type date or click in the icon ActionDateRange to open the material-ui datepicker. |
@canastro I had not really thought about using a |
This is important for accessibility (WCAG Level A). Having the option to manually enter a date string would be fantastic. I saw another Material implementation (that I don't remember now!) where they had a text input field, with an icon that opened the date picker. Best of both worlds. |
@markau could you point to that other implementation? Maybe we could adapt it and bring it here. |
@rigelk, it seems I was mistaken saying it is Material implementation, but it does use React. |
here is my implementation: mui/material-ui#5677 I would appreciate any feedback |
Also mui/material-ui#5030 has been open with a working and production tested implementation since August |
Yeah, any expectation when mui/material-ui#5030 will be closed? We are eager to use it. |
Here is my solution: https://github.com/barbalex/apf2/blob/master/src/components/shared/DateFieldWithPicker.js Basic idea:
Because I use moment.js to parse the date string
users have a lot of possibilities:
|
@barbalex, I am trying to get your example to work in a react typescript project, but getting error on datePicker ( Property 'datePicker' does not exist on type 'MyDatePicker') used in StyledFontIcon's onClick method and DatePicker's ref method. Would you know how to solve this? Could you also make a standalone react typescript component for your datepicker? |
Sorry: I use flow. I have never worked with typescript. Property 'datePicker' is created by a ref (https://github.com/barbalex/apf2/blob/master/src/components/shared/DateFieldWithPicker.js#L168-L171). You may have not created the ref properly. I usually use functions for my components. In this case I use a class because ref's usually don't work in functions. Maybe it does not work for you because you are not using a class? |
@reinartg it is kind of funny that flow also does not recognize the property created by a ref which is why I had to find a way to quiet it's complaints: https://github.com/barbalex/apf2/blob/master/src/components/shared/DateFieldWithPicker.js#L169 |
Thank's to all, that's something that I've been looking for. I've simplified barbalex's component removing unnecessary (in my opinion) dependencies. That's the component that I'm currently using (material-ui ver 0.18.6) : 'use strict';
import React, {Component} from 'react';
import {DatePicker, IconButton, TextField} from "material-ui";
import ActionDateRange from 'material-ui/svg-icons/action/date-range';
import format from 'date-fns/format'
import parse from 'date-fns/parse'
export default class DatePickerField extends Component{
constructor(props){
super(props);
this.state = {
selectedDate: new Date(),
dateText: format(new Date(), 'MM/DD/YYYY')
};
}
handleChangeDatePicker = (event, date) => {
this.setState({selectedDate: date, dateText:format(date, 'MM/DD/YYYY')});
};
handleDateInputChange = (event, value) => {
this.setState({dateText:value});
};
handleDateInputBlur = (value) => {
let parsedDate = parse(value, 'MM/DD/YYYY');
if(this.isADate(parsedDate)){
this.setState({selectedDate:parsedDate});
}
else{
this.setState({dateText:format(this.state.selectedDate, 'MM/DD/YYYY')});
}
};
isADate = (maybeDate) => {
if ( Object.prototype.toString.call(maybeDate) === "[object Date]" ) {
if ( isNaN( maybeDate.getTime() ) ) {
return false;
}
else {
return true;
}
}
else {
return false;
}
};
render(){
let dateInputWidth = "150px";
let datePickerMargin = "-185px";
return (
<div style={{display: "flex"}}>
<TextField
style={{width:dateInputWidth}}
value={this.state.dateText}
onChange={this.handleDateInputChange}
onBlur={(event) => this.handleDateInputBlur(event.currentTarget.value)}
/>
<IconButton style={{opacity:"0.65"}}
onClick={() => this.datePicker.focus()}>
<ActionDateRange />
</IconButton>
<div style={{width:"0px", height:"0px", marginLeft:datePickerMargin}}>
<DatePicker
id="dataPicker"
floatingLabelText={''}
value={this.state.selectedDate}
errorText={''}
disabled={false}
formatDate={date => { return format(date, 'MM/DD/YYYY') } }
autoOk
container="inline"
fullWidth
onChange={this.handleChangeDatePicker}
ref={c => {
this.datePicker = c
}}
/>
</div>
</div>
)
}
} |
Closing for mui/material-ui#4787 |
The only thing preventing me to use the date picker from material-ui is the fact that the user is not capable to use keyboard to write a date.
Sometimes its just faster or more suitable to just use keyboard to select dates.
Imagine a scenario where the user has a form with a lot of TextFields, he can keep pressing tab and filling the form, but once he encounters a Date picker he needs to use the mouse to open the date picker... And if wants to select a really old date he will have a nightmare selecting the year... Its just not nearly as fast as just typing it.
Related issue mui/material-ui#5612.
The text was updated successfully, but these errors were encountered: