-
-
Notifications
You must be signed in to change notification settings - Fork 739
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
add support for changing years #52
Comments
Hi this is not the first time I get this request ... I'm not sure how we should implement it. The example of the year calendar is an idea. How often enough would a user want to change the year? Could you provide some use case? :) |
In my app I need it to pick the year a friend was born and to add historic events (this day in history kind of trivia). I can also see something like a resume building app where you pick the month+year for when you started/ended some job. If we default to today and the job started 5 years ago and ended 3 years ago it's going to be a real pain to add the 2 dates. The year calendar idea could have an extra step:
and then, clicking on the 2015 caption, you get the year calendar:
|
Hi @terebentina, I believe I've seen this UI pattern already in another date picker, however I don't like it in terms of usability 😌 In your case, for example, you may better provide three day/month/year selects and use perhaps the day-picker as an aid to select the day. A date picker is not the only nor the best way to input a date, and I'd like to avoid complex solutions that don't provide good usability. What do you think? |
Ughh, selects...and 3 of them? Yuck! :) How about this: Not sure about your concerns regarding usability...I am a windows & android user and on both the calendar is pretty much using this pattern. Maybe I got used to it... |
Hi 👍 We need it. A common simple use case would be to select a birth date. Regards, |
To be honest I believe this is not the component you are looking for: date pickers like these help to identify a day inside a month (e.g. by looking to its weekday), or to select a range, or to understand which days are "enabled" or not. How should the weekday help the user? "Yes, it must be this day because i was born on Sunday"? Selects or even text fields (maybe with In particular this one is called day-picker because it was born to select a day, not a month or even a year :-) Adding the ability to select month/year implies a lot of work: layout, styling, unit tests, keyboard navigation... if it's not worth it we have no reason to make this component more complex. I'd like however to see some good implementations including this feature. |
(There is however a |
@gpbl, i really like your date picker. But i will have to layer it up with year/month selection as well in my case. It seems like most date pickers require this functionality no matter if you agree with user experience or not. |
I understand where you're coming from @gpbl, but I agree that a faster way to change months/years would be good. I think the challenge here is making a good design. And I wonder if it's possible to fit in nicely with this component or not. Just for the sake of discussion, you can try this link out in Chrome to see how they do date selection: http://jsfiddle.net/mhmq3mkz/. |
Very interesting @jkillian, browsing the internet I've never used a date picker like that. I believe the amount of work for doing something like that is not worth it. Wouldn't be a better design to show two |
@gpbl your example is certainly acceptable for me. |
So maybe we have found a solution 🙌 But when should we make the selects disappear? I'm thinking to remove the |
Not very related to this issue but since you brought close into discussion, there are 2 more buttons that I miss, besides close: Regarding i18n you could add And showing/hiding selects could be done with props like |
@terebentina thanks for the sharing your ideas – those features are unlikely to be implemented since they are restricted to particular use cases. As you say, it's not hard to wrap the DayPicker inside a component, and I'd prefer the developer to follow this way instead of adding lot of new props to it. Anyway I was thinking about the form pictured above, so this is how I'd implement it. First I create the function YearMonthForm({ currentDate, onChange, onSubmit }) {
const years = [2010, 2011, 2012, 2013, 2014, 2015];
const months = dateUtils.getMonths();
const currentMonth = currentDate.getMonth();
const currentYear = currentDate.getFullYear();
const handleChange = function(e) {
onChange(new Date(e.target.form.year.value, e.target.form.month.value));
}
return (
<form onSubmit={ onSubmit }>
<select name="month" onChange={ handleChange }>
{
months.map( (month, i) =>
<option key={i} value={i} selected={ currentMonth === month}>
{month}
</option>
)
}
</select>
<select name="year" onChange={ handleChange }>
{
years.map( (year, i) =>
<option key={i} value={year} selected={ currentYear === year}>
{year}
</option>
)
}
</select>
<button type="submit">OK</button>
</form>
)
} In a class MyComponent extends React.Component {
state = {
canChangeYear: false,
selectedDay: new Date()
}
render() {
const { canChangeYear, selectedDay } = this.state;
return (
<DayPicker
ref="daypicker"
canChangeMonth={ !canChangeYear }
onDayClick={ (e, day) => this.setState({ selectedDay: day }) }
onCaptionClick={ () => this.setState({ canChangeYear: true }) }
captionNode ={ canChangeYear &&
<YearMonthForm currentDate={ selectedDay }
onChange={ month => this.refs.daypicker.showMonth(month) }
onSubmit={ () => this.setState({ canChangeYear: false }) }/>
}
/>
)
}
} If not null, the new I like this approach because the interaction between form and DayPicker is left to the developer (e.g. he could attach some events on the select elements, disable months for specific times, etc). |
@gpbl I like this approach with the new |
@gpbl not really a fan of that approach because it still requires a lot of clicks to quickly move around in time (try going to 1970...) |
@adidahiya I'm working on an example with the select elements, using a new |
@gpbl nice! we'll try this out soon, likely next week |
With the new PS. @adambbecker perhaps this change is interesting to you? I've seen Calypso implementing a navigation between years in the date picker, I guess with some CSS positioning workaround. |
Using the new |
Oh nice! Thanks @gpbl for the heads up, this will certainly prove quite useful and a much more elegant solution. |
@gpbl can we use captionElement in DayPickerInput? |
@gpbl How to have a custom header/year selector as shown in above images? |
It would be nice if we could switch the years somehow, without spamming the next/prev month links.
Either an extra pair of <</>> where the next/prev months are, or maybe a select box for years in the caption, or even a click on the caption to show an year sort of calendar (with just clickable years).
Something like:
The text was updated successfully, but these errors were encountered: