Skip to content

add isDisabledDate #113

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

Merged

Conversation

stinger567
Copy link
Contributor

added the ability to enable and disable dates, using isDisabledDate function: #110

If this is not how you wanted it implemented, and would prefer a different way let me know and I can change it.

@probablykasper
Copy link
Owner

The thought was to havs isDisabledDate as the API. Having it as an implementation detail might just be unnecessarily bad performance

But I see now that you might want to reactively update the enabled/disabled dates (right?), so then I'm not sure what API is best. I don't love the idea of having to create an array of disabled dates

@probablykasper
Copy link
Owner

I think an isDisabledDate prop is best

@stinger567
Copy link
Contributor Author

Yeah, I would want it to be reactive. I re-worked it to use a isDisabledDate prop, let me know if this is better?

Copy link
Owner

@probablykasper probablykasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but it's still possible to select disabled dates by typing, using arrow keys and probably by switching the month/year

How it should probably work:

  • When updating from oldDate to newDate:
    • If newDate is newer, go forward to the next enabled date
    • If newDate is older, go back to last enabled date

@stinger567
Copy link
Contributor Author

That was an oversight on my part, I have put in a fix that should now prevent a disabled date from being selected by typing or by the arrow keys.

@probablykasper
Copy link
Owner

I found an issue when using the DateInput. When setting the DateInput's value, it's not affected by isDisabledDate for some reason (added a button to test it in my latest commit)

It seems like the updated DateInput value never reaches the DatePicker, so they go out of sync. Surely not caused by your code, I wonder if it's a Svelte 5 issue maybe

@stinger567
Copy link
Contributor Author

stinger567 commented Mar 31, 2025

Oh I see now, yeah I did overlook that case.

@probablykasper
Copy link
Owner

btw, if you feel like converting to runes syntax would fix it, I have nothing against dropping Svelte 3/4 support

@stinger567
Copy link
Contributor Author

After looking at it more, updating to runes wouldn't help, DatePicker is behind an if statement so it doesn't load till the date input is clicked to open it. Setting the date through the DateInput will never pass the date to the DatePicker. Also since DatePicker can be used separably, the date just needs to be check in both DateInput and DatePicker. I moved the toValidDate function to the date-utils file, then used it in both DatePicker and DateInput, it fixes the issue. If you would prefer it done a different way let me know.

@probablykasper
Copy link
Owner

Ah makes sense, very great work!

@probablykasper probablykasper changed the title add enableDate and disableDate add s Apr 2, 2025
@probablykasper probablykasper changed the title add s add isDisabledDate Apr 2, 2025
Copy link
Owner

@probablykasper probablykasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very great work

@probablykasper probablykasper merged commit 9848985 into probablykasper:master Apr 2, 2025
1 check passed
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.

[Request] Disable dates Ability to disable certain date/s and/or ranges or date
2 participants