Skip to content
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

Allow to select date or range dates programatically with value attribute #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brunoprietog
Copy link

@brunoprietog brunoprietog commented Mar 6, 2024

Hey there, thanks for the project!

We're integrating this element to have an accessible datepicker. However, we need to be able to have a date selected from the beginning.

The main use case is an edit form, where there's already a date previously selected and we want to allow to select another one. The selected date must be clearly marked, the start-date attribute isn't enough.

Another scenario is to support a change coming from the server, for example, making column filters in a table, filtering by date. In our case we use morphing for most of the inputs and it was easy to prevent the algorithm from touching the element so that it doesn't lose state. But still, ideally it should be resistant to changing the value attribute so that integration can be simpler.

I also thought about converting the private method updateValue to public, but I think that being able to define it from the HTML or JavaScript indistinctly is more consistent.

There's the possibility of using the public method parseDate, but it doesn't support ranges. If it's useful for that method to accept them too, I could do it in another PR.

Now you can initialize the element in the following 2 ways, with the selected date or with the selected date range:

<inclusive-dates id="datepicker" value="2024-01-01"></inclusive-dates>
<inclusive-dates id="range-datepicker" range="true" value="['2024-01-01', '2024-01-05']"></inclusive-dates>

It can also be seen in action on the demo page.

Copy link

vercel bot commented Mar 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
inclusive-dates ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 6, 2024 6:38am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant