How I built a date picker
decoding.io
decoding.io
There is really no way to implement this in JS anyway because all major browsers have native date pickers by now: https://caniuse.com/input-datetime
Yes, you do want to be careful about accessibility here, but it’s emphatically not a “please please please don’t do this” situation. Because its essence is just a text box, the accessibility of what’s been made here is probably actually excellent, and if it’s not, it should require only minor tweaks to make it so. You very probably actually don’t want to expose the popup in any way—for what I see, doing literally nothing for accessibility will probably be better in most instances than doing something.
It's not. The whole thing is in a <table>, there's no ARIA attributes let alone ones that reflect states, and the buttons are...<li>'s?
> doing literally nothing for accessibility will probably be better in most instances than doing something
This is a great example of why that's true. If the author had referenced any of the best practices for this, they wouldn't have ended up with such a bad result.
https://www.w3.org/TR/wai-aria-practices-1.2/examples/combob...
I’d be interested to see what a regular user of accessibility stuff would find of this stuff. I think both approaches are perfectly reasonable, with the don’t-expose-the-popup-at-all side possibly even preferable for some.
A11y and web components are well studied, start from the best practices, and if you deviate, have a good reason why that's supported by testing.
First of all
Input type=date
On Android shows a date picker that many users have found confusing to operate. They can't figure out how to select the year. I used to say "not my problem" but it actually was because they still complained.So
Input type=month
Solves that first problem and then a day selector does the rest but that's an unfamiliar paradigm so...I wanted year/month/day in a way that uses will find easy. One for each then.
There's many existing options and they use a lot of code. I mean just an insane amount. I don't want a boatload of code to select a date in a way that users won't complain.
The browser already knows everything about dates, so we can just ask it how many days are in a month and what the name of the month is.
Leap years, leap seconds, it's all in there. No wheel reinventing necessary
So we have one of our two key lines
let maxday = new Date(year, month, 0).getDate();
(It'll be further explained at the end.)2nd part; let's not have an array of month names. Instead, let's ask the browser for what the user calls the months based on their first language:
Intl.DateTimeFormat(
navigator.languages[0],
{month: 'long'})
.format( new Date(startyear, i) )
So they select the year, then the month, then we use that as a query to find out how many days are in the month by asking the default Date object, already built in.And all together now https://gist.github.com/kristopolous/d956c148ddcb628d54ec511...
Btw, this is for a product related to driving a car so we aren't dealing with blind users. A lot of accessibility things were skipped
At least allow a date to be pasted in and have the logic to accept if the user has entered something thats different from what the backend needs but makes sense for the the current date and their locale: "22 feb" "22/02/2022" "22/2" "2/22" etc
e.g. : "2 feb" and it says "2 feb, 2022, 6 days from now"
write "3/2/2022" and it refuses to validate, but lets you select "2 feb, 2022" or "3 mar 2022" to replace to continue.
Date pickers are horrendous UX, IMHO for so many reasons. Text is so much better.
As a user, every time I see one, I groan and fight it instead of liking to use it.
But I haven't seen any A/B tests. Does date picker really improve user experience?
Under these considerations, I can say that for a "well known" date, like a birthday, or an expiration date, where the context of the calendar doesn't matter, it's not needed, and probably undesirable. (Under these contexts I would use bare selects/inputs with one for each of YYYY/MM/DD.)
For an appointment, or a time span? Date pickers are useful. “Which days are mondays?” “I want to book from a monday to the friday the next week.” Raw controls won't provide the context to help the user.
I feel the ones you fight against are more than likely those where you already are aware of a precise moment, in the first scenario. The others are more likely to leave no impression if well done.
With that said: Always de-compose the date picker in their discrete parts that a user can use. Make the picker fill these.
Yes, I hate when I see a date picker for birthday. I don't need to pick a date on birthday!
But when it's meeting or airplane ticket, it makes sense.
So, picker is good when you don't actually know the date yet.
OK, thanks!
There is one, it is a standard, it is a format, it is "an international standard covering the worldwide exchange and communication of date- and time-related data". But not everyone uses it.
I think they would be good where additional info can be inlined such as existing events.
But without those advantages I prefer to type it. Especially date of birth!! A year older is another 10px to scroll!
I like date pickers especially for when I need help deciding a date, e.g. when booking a haircut: I don't know exactly what day I want to go in, but I'll know it when I see it.
Date pickers are also useful for ranges of dates (although the UX for these is hit-and-miss), since it helps visualize duration nicely and always makes it easier to pick an end date.
I'm 50/50 when it comes to a date that I know, but usually, I'll prefer a ISO8601 input field for that.
Use a text entry field, validate it with a regex, and have an error message that says "YYYY-MM-DD plz" if it fails the regex.
Nothing drives me crazy like a credit card number field that tells _me_ to remove the spaces or hyphens from the number. Like what, the computer can't do that for me?
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/in...
Sunday is actually the first day of the week (i.e. column index = 0) in almost every calendar I've used. Perhaps this varies by culture/locale?
I've always thought of Monday as the first day of the week. It's the day that starts the workweek (and school week) and Sunday is part of the weekend.
https://support.microsoft.com/en-us/office/weekday-function-...
It is very user unfriendly to choose a date of something like a birthdate with a picker.