-
-
Notifications
You must be signed in to change notification settings - Fork 7k
feat(VDatePicker): disable months and years if not allowed #21466
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
Conversation
As mentioned in the PR description, this works only when I'm open for suggestion on how we can implement this (without heavy computation) for cases when |
By "heavy computation" you probably meant those years. // check if month is accepted by allowedDates
const firstDay = adapter.parseISO(`${year.value}-${month}-01`)
const monthSize = adapter.diff(
adapter.endOfDay(adapter.endOfMonth(firstDay),
adapter.startOfDay(firstDay)
)
return createRange(monthSize)
.find((i) => props.allowedDates(adapter.addDays(firstDay, i)))
// up to 31 executions per month in the grid -- OK'ish // check if year is accepted by allowedDates
const firstDay = adapter.parseISO(`${year.value}-01-01`)
const yearSize = adapter.diff(
adapter.endOfDay(adapter.endOfYear(firstDay),
adapter.startOfDay(firstDay)
)
return createRange(yearSize)
.find((i) => props.allowedDates(adapter.addDays(firstDay, i)))
// up to 366 executions per year in the grid --- hm... Let's consider real life scenarios:
I would vote for including it and wait for feedback. We might first and foremost learn about scenarios that suffer from performance hit - learning about those is a benefit for the community and might exceed the risk of upsetting devs. Once we get some signals, we'd have couple of options to choose from:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
For some reason this is calling allowedDates 2061 times instead of just 365
×152 years is over 55000 calls, should we only do this if min and max are explicitly set? |
both branches of allowedMonths already check the year
I just tested for worst case senario and Maybe you mixed it up with calls from |
My last commit fixed it.
Well yeah it doesn't matter how many times a specific function calls it directly, only how many times it is invoked overall. |
Sounds fair, should we mention this somewhere in the documentation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved pending added unit test.
fixes #20465
Description
Disable month and year buttons based on
allowed-dates
prop when:allowed-dates
is arrayallowed-dates
is function (open for suggestion/help)Markup:
Screenshots