day8 / re-com

A ClojureScript library of reusable components for Reagent
https://re-com.day8.com.au
MIT License
796 stars 146 forks source link

Add a placeholder to datepicker-dropdown #116

Open p-himik opened 7 years ago

p-himik commented 7 years ago

Similar to HTML input's placeholder attribute. I think all that's needed is a new parameter description to datepicker-dropdown-args-desc and a corresponding argument to anchor-button.

Gregg8 commented 7 years ago

Could you elaborate on this (or provide a PR)? Do you want to place something like "Enter date" there? I'm wondering why this is better than just providing a default date to model. In which case, would you seed model with nil? So when they open the calendar, what date would they see? No date or today's date? If today's date, I presume you would immediately feed that into model?

Our general philosophy is to never leave a component in an undefined or invalid state.

p-himik commented 7 years ago

Sure, I'll provide a PR when and if we have an agreement on how to implement it (if at all). Yes, something like "Enter date". In my particular case, I have two date fields in a small space with placeholders "From" and "Till". The default date says nothing about semantics. While one, of course, can provide an external label, it's not always an optimal solution (e.g. not coherent with other design elements, or tight space requirements). Yes, the model would be nil, maybe also an empty string (value of a not filled date input in Google Chrome is an empty string). When you open the calendar, you'd see no date selected, and maybe a small hint on the current day (again, just as Google Chrome shows date input).

In my understanding, nil is not an undefined state - it's the state without any date selected. The parameter :model can be explicitly set to nil - nothing undefined about it, in my opinion.

hipitihop commented 8 months ago

@kimo-k @Gregg8 In our apps-lib variant(s) I had a similar usecase. The dropdown date range picker (also using a from and to with 2 pickers) is used as a filter criteria in which context it is optional to specify, hence :model is nil and in my specific example I wanted to show "Include all dates" in the label. I implemented a parameter :label-when-none with a default of an empty string, so that it behaves as normal for backward compatibility. What do we feel about this approach ?