StackExchange / Stacks

Stack Overflow’s Design System
https://stackoverflow.design
MIT License
610 stars 90 forks source link

New Feature: Date Picker #188

Open TedGoas opened 5 years ago

TedGoas commented 5 years ago

Is your feature request related to a problem? Please describe. Stack Overflow has a few instances of a data picker. The current solutions are all different (jQuery UI) and not very robust.

Describe the solution you'd like A date picker in Stacks that includes:

  1. A few predefined ranges.
  2. Support for custom date ranges.
  3. Theming support (eg. Enterprise, network sites)

Describe alternatives you've considered jQuery

Additional context @UXPiper worked on a few mockups here and here:

screen shot 2018-11-19 at 4 11 07 pm
UXPiper-zz commented 5 years ago

This is the final design spec: https://stackexchange.invisionapp.com/share/MTP7KOWEZ7R#/332358366_SO-Stacks--v01__Design-Spec__Date-Picker

dancormier commented 3 years ago

PLATENG-734

UPDATE

I linked to a Jira issue and decided to put my notes there. That doesn't make much sense considering this is a Stacks component discussion we're having.

The next few comments are my notes (and some helpful input from @bnickel) ported from the Jira issue.

dancormier commented 3 years ago

From Jira, @dancormier commented 5 days ago:


vanillajs-datepicker

A quick search lead me to vanillajs-datepicker, which looks pretty badass* overall.

*badass in this context means accessible, configurable, and full featured.

Size

I did a back-of-the-napkin calculation and found the minified CSS + JS to land around 10-11KB†

†I need to verify this and this may depend on which features we’d like to include in our component.

Features

Maintenance

Potential issues

dancormier commented 3 years ago

From Jira, @dancormier commented 5 days ago:


flatpickr

Features

Maintenance

Potential issues

Investigate

dancormier commented 3 years ago

From Jira, @bnickel commented 5 days ago:


For awareness, here’s some places where we use date pickers today and ones with nuance. We generally, but not always, deal with date ranges.

https://stackoverflow.com/admin/community-events

20210802-135016

This is the only scenario I know of where time is involved. Also the only one where we display in local timezone.

https://stackoverflow.com/admin/user-activity

20210802-135121

https://stackoverflow.com/admin/analytics

20210802-135129

https://stackoverflow.com/ads/sponsorships/add

20210802-135138

https://stackoverflow.com/cm/elections/add

20210802-135142

This one only lets you pick Tuesdays.

https://stackoverflow.com/events/core

20210802-135146

This one uses the native date input.

Channels admin

20210802-135151 20210802-135154

These ones support an unbounded date.

Enterprise

Enterprise has some date pickers and I believe a custom component, but I’ve not looked into those.


Then I thanked Brian.

dancormier commented 3 years ago

From Jira, @dancormier commented 3 days ago:


<input type="date">

So, yeah we might be better off starting with a good, old fashioned <input type="date">. Seems like it would do the job when it comes to most of the date inputs we already have littered across the site.

If we went this route, we could start with this native input and bring in a different solution when it’s needed. I’d consider this the YAGNI approach.

Handy references

Features

Potential issues

aaronshekey commented 3 years ago

Thanks for gathering this info, @dancormier. Seems like we could refactor to native date inputs on the way to something more fully-featured / customizable. Leaning toward Vanilla?

dancormier commented 3 years ago

@aaronshekey yep, leaning vanilla for sure. I think it will meet most of our needs and can be extended if we absolutely need it*. If we're okay with working with a simplified picker to start, vanilla is probably the flavor we want.

*I'm thinking in the case of the one date picker at /cm/elections/add that only allows Tuesdays.

dancormier commented 3 years ago

TL;DR: I advise we implement the date picker without third party libraries and stick with a native <input type="date" />.

Requirements and goals

Based mostly on the existing implementations provided by @bnickel, it seems like our requirements largely overlap from one implementation to another.

Common requirements

Must have

Nice to have

One-off requirements

Here are some features implemented in individual existing date pickers on our products:

Findings and recommendations

I'd advise replacing current date picker implementations with <input type="date"> in the interum (at least). This way, we can provide the user with a consistent, dependable, lightweight date picker and extend (or replace) it at a later date if the need arises.


Clear advantages

Using a native input with no third party libraries has clear advantages over third party implementations:

Likely advantages

It seems a native input will excel at:

Disadvantages/compromises

There are a few compromises if we go with a native input:

*Including time selection in the date picker

Many third-party JS date pickers include an option add time selection to the date input. If we go the vanilla route, we might be able to get away with the picker just being HTML and CSS. We have a couple options if we go the vanilla route:

Using <input type="datetime-local" />

This could be an input type we support and endorse in addition to date. At the time of this writing, it's supported in all browsers Stacks supports except Firefox... BUT, after digging into a 5 year old bug report, it looks like Firefox support is on it's way (as of 2 days ago 😮).

See also Date and time input types | Can I use...

Using separate <input type="date" /> and <input type="time" /> inputs

This is probably the best vanilla option initially. It would allow us to replace existing date and time pickers with a lightweight, well-supported option.